Question

In: Computer Science

Task 6: Using whatif and confirm Windows PowerShell allows administrators to safely test and use commands....

Task 6: Using whatif and confirm

Windows PowerShell allows administrators to safely test and use commands. In this step, you will use the whatif and confirm commands.

The [Command] -WhatIf flag shows you the results without actually performing the action.

The [Command] -Confirm flag asks you to confirm the operation before it executes.

1. Type the following command, and then press ENTER to see a list of services that would be stopped if you ran the Stop-Service command.

PS >Stop-Service M* -WhatIf

A list of services that would be stopped is displayed.

2. Type the following command, and then press ENTER to confirm whether or not to stop each service.

PS >Stop-Service M* -Confirm

For each service beginning with M, you will be asked if it should be stopped. For this lab, reply No in each case.

Task 7: Creating and manipulating variables

In this step, you will work with variables in Windows PowerShell. You will learn about their declaration, usage, and behavior.

1. To create a variable to hold a string value, type the following command, and then press ENTER.

PS >$var = "Hi there"

With this command, you created a variable named var, and you assigned the string value Hi there to it.

A variable in Windows PowerShell must begin with the dollar sign ($). If special characters are needed in a variable name, curly braces can be used to surround the variable name ({}).

2. To output the value stored in this variable, type the following command, and then press ENTER.

PS >$var

A better way to output variable values is to use a cmdlet named Write-Host before the variable name, clearly showing it will output the values to the host.

PS >Write-host $var

By default, a variable will have a null value. Null values in Windows PowerShell are represented as $null.

3. Variables in Windows PowerShell can be listed and accessed under a special location. To display the list of currently declared variables, type the following command, and then press ENTER.

PS >Get-Variable

4. By default, variables in Windows PowerShell are non-typed, which means they can hold an arbitrary value. To change the variable value and type to an integer, type the following command, pressing ENTER after each line.

PS >$var = 123

PS > $var Now the variable is holding the integer value 123.

  1. Variables can also contain lists (similar to arrays). To change the value to an array of integers, type the following commands, pressing ENTER after each line.

PS >$var = 1,2,3

PS > $var This time, the variable is holding an array of integers.

  1. To see the new type of the variable, type the following command, and then press ENTER.

PS >$var.GetType().FullName

The variable is now an array object of type System.Object[].

Arrays can be also manipulated through their .NET methods. For example, they can be queried on their length.

7. To use the Length property to retrieve the number of elements of the array, type the following command, and then press ENTER.

PS >$var.Length

The size of the array is displayed.

8. You can also access individual elements within an array by using square brackets ([]). To retrieve the second element of the array, type the following command, and then press ENTER.

PS >$var[1]

Arrays in Windows PowerShell are zero-based, which means that the first element will always be at position (index value) 0. The value of the second element of the array is displayed.

9. You can also type a variable by prefixing its declaration with the desired data type name. To re-declare the variable as an array of integers, type the following command, and then press ENTER.

PS >[int[]] $var = (1,2,3)

10. To assign the string value 0123 to the third element of the array, and then display it, type the following commands, pressing ENTER after each one.

PS >$var[2] = "0123"

PS > $var[2]

11. When an implicit conversion is not available, it displays an error. To attempt to set a string value that cannot be converted, type the following command, and then press ENTER.

PS >$var[2] = "A string value"

The error is displayed.

Solutions

Expert Solution

Executed all commands as asked. Please consider upvoting

1. Type the following command, and then press ENTER to see a list of services that would be stopped if you ran the Stop-Service command.

PS >Stop-Service M* -WhatIf

2. Type the following command, and then press ENTER to confirm whether or not to stop each service.

PS >Stop-Service M* -Confirm

Task 7: Creating and manipulating variables

In this step, you will work with variables in Windows PowerShell. You will learn about their declaration, usage, and behavior.

1. To create a variable to hold a string value, type the following command, and then press ENTER.

PS >$var = "Hi there"

2. To output the value stored in this variable, type the following command, and then press ENTER.

PS >$var

A better way to output variable values is to use a cmdlet named Write-Host before the variable name, clearly showing it will output the values to the host.

PS >Write-host $var

By default, a variable will have a null value. Null values in Windows PowerShell are represented as $null.

Variables in Windows PowerShell can be listed and accessed under a special location. To display the list of currently declared variables, type the following command, and then press ENTER.

PS >Get-Variable

4. By default, variables in Windows PowerShell are non-typed, which means they can hold an arbitrary value. To change the variable value and type to an integer, type the following command, pressing ENTER after each line.

PS >$var = 123

  1. Variables can also contain lists (similar to arrays). To change the value to an array of integers, type the following commands, pressing ENTER after each line.

PS >$var = 1,2,3

PS > $var This time, the variable is

To see the new type of the variable, type the following command, and then press ENTER.

PS >$var.GetType().FullName

7. To use the Length property to retrieve the number of elements of the array, type the following command, and then press ENTER.

PS >$var.Length

The size of the array is displayed.

8. You can also access individual elements within an array by using square brackets ([]). To retrieve the second element of the array, type the following command, and then press ENTER.

PS >$var[1]

Arrays in Windows PowerShell are zero-based, which means that the first element will always be at position (index value) 0. The value of the second element of the array is displayed.

9. You can also type a variable by prefixing its declaration with the desired data type name. To re-declare the variable as an array of integers, type the following command, and then press ENTER.

PS >[int[]] $var = (1,2,3)

10. To assign the string value 0123 to the third element of the array, and then display it, type the following commands, pressing ENTER after each one.

PS >$var[2] = "0123"

11. When an implicit conversion is not available, it displays an error. To attempt to set a string value that cannot be converted, type the following command, and then press ENTER.

PS >$var[2] = "A string value"

The error is displayed.


Related Solutions

Research the Windows PowerShell commands for manipulating the firewall and construct a command that lists all...
Research the Windows PowerShell commands for manipulating the firewall and construct a command that lists all the firewall rules on a system with the output containing the information and headers below: Rule name TCP port Enabled
Windows PowerShell Scripting Please answer using a switch statement. I have asked this question already and...
Windows PowerShell Scripting Please answer using a switch statement. I have asked this question already and it was wrong. Thank you and I will upvote. 1) Write a PowerShell script that displays the total count of each type (dll, txt, log) of files in c:\windows using switch statement.
Using PyCharm Edu on Windows, need to ask for an IP address (input), use "ipaddress.ip_address" to...
Using PyCharm Edu on Windows, need to ask for an IP address (input), use "ipaddress.ip_address" to validate it, only if error (value or type) set the default IP to 192.168.1.1, if no error then use the original input. This is the code so far and I need help please. def req_Address(): while True: try: address = str(ipaddress.ip_address(input("Please enter the ip address you wish scan [192.168.1.1]: "))) except (ValueError, TypeError): print("Not a valid IP address") else: print("Setting the default address to...
PART 7: Explore some new commands using man and then attempt to use them: w, who,...
PART 7: Explore some new commands using man and then attempt to use them: w, who, whoami clear reset date TRY date +%Y cal exit shutdown NOTE: We must not shutdown the general.asu.edu and only root can do it! wc let TRY  age=2019-1980 echo TRY  echo 'I am' $age 'old!'  and TRY echo -n 'HELLO!' printf grep TRY w | grep bjlauer | wc -l  NOTE: use your username rather than mine env ALSO TRY  echo $LOGNAME set history TRY  history 50 > file.200 groups id...
The value for Qcrit using the HSD test for 6 groups with 6 subjects in each...
The value for Qcrit using the HSD test for 6 groups with 6 subjects in each group andα=0.01 is _________. 5.24 4.30 4.23 5.37
Explain using examples how the use of swap contracts allows for comparative advantage Explain using examples...
Explain using examples how the use of swap contracts allows for comparative advantage Explain using examples how the use of swap contracts allows for comparative advantage
Task 6 Assess possible events that might affect these markets. Use the IS LM BP model...
Task 6 Assess possible events that might affect these markets. Use the IS LM BP model to frame your analysis:-What if: There was either expansionary fiscal or monetary policy What if relative interest rate rise (fall) What if social and political concerns impact trade Task 7 How exposed is the market to external shocks (e.g trade flows / NX) How exposed is the economy to internal shocks (eg. fluctuations in demand for money / regional shocks ) Specify the exchange...
Using NetBeans IDE, write a JavaFX application that allows theuser to choose insurance options. Use...
Using NetBeans IDE, write a JavaFX application that allows the user to choose insurance options. Use a ToggleGroup to allow the user to select only one of two insurance types—HMO (health maintenance organization) or PPO (preferred provider organization). Use CheckBoxes for dental insurance and vision insurance options; the user can select one option, both options, or neither option. As the user selects each option, display its name and price in a text field; the HMO costs $200 per month, the...
Using the following data (already sorted), use a goodness of fit test to test whether it...
Using the following data (already sorted), use a goodness of fit test to test whether it comes from an exponential distribution. The exponential distribution has one parameter, its mean, μ (which is also its standard deviation). The exponential distribution is a continuous distribution that takes on only positive values in the interval (0,∞). Probabilities for the exponential distribution can be found based on the following probability expression: . Use 10 equally likely cells for your goodness of fit test. Data...
Create a 6 by 6 checkered pattern without using a loop. Also use the wait and...
Create a 6 by 6 checkered pattern without using a loop. Also use the wait and offset properties. Create every checkered spot with a 1 second wait time. VBA Excel
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT