PS C:/Documents and Settings/somebody> cd c:/
PS C:/> dir
PS C:/> md c:/test
PS C:/> cd c:/test
PS C:/test> fsutil file createNew c:/test/myNewFile.txt 1000
File c:/test/myNewFile.txt is created
PS C:/test> dir
PS C:/test> del *.txt
PS C:/test> cd c:/
PS C:/> rd c:/test
PS C:/> ipconfig /all >ipconfig.txt
PS C:/> notepad ipconfig.txt
PS C:/> ipconfig /all >tshoot.txt; route print >>tshoot.txt; netdiag /q >>tshoot.txt; net statistics workstation >>tshoot.txt;
cmdlets arguments :-whatif,-confirm
PS C:/> get-process note*
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
------- ------ ----- ----- ----- ------ -- -----------
65 7 1648 6724 79 0.37 5124 notepad
PS C:/> notepad
PS C:/> get-process note*
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
------- ------ ----- ----- ----- ------ -- -----------
65 7 1648 6724 79 0.37 5124 notepad
66 7 1656 6128 91 0.06 5428 notepad
PS C:/> stop-process -id 5428 -whatif
What if: Performing operation "Stop-Process" on Target "notepad (5428)".
PS C:/> stop-process -id 5428 -confirm
Confirm
Are you sure you want to perform this action?
Performing operation "Stop-Process" on Target "notepad (5428)".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): y
PS C:/> exit
PS C:/> Export-Console myconsole
PS C:/> PowerShell -version 1
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.
PS C:/> PowerShell -version 2
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.
PS C:/> PowerShell -version 3
Cannot start Windows PowerShell version 3 because it is not correctly installed.
PS C:/> PowerShell -nologo
PS C:/> PowerShell -psconsolefile myConsole.psc1
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.
#
Parameter
Meaning
-whatif
Tells the cmdlet to not execute but to tell you what would happen if the cmdlet were to run
-confirm
Tells the cmdlet to prompt before executing the command
-verbose
Instructs the cmdlet to provide a higher level of detail than a cmdlet not using the verbose parameter
-debug
Instructs the cmdlet to provide debugging information
-ErrorAction
Instructs the cmdlet to perform a certain action when an error occurs. Allowed actions are: continue, stop, silentlyContinue, and inquire.
-ErrorVariable
Instructs the cmdlet to use a specific variable to hold error information. This is in addition to the standard $error variable.
-Outvariable
Instructs the cmdlet to use a specific variable to hold the output information
-OutBuffer
Instructs the cmdlet to hold a certain number of objects before calling the next cmdlet in the pipeline
Note To get help on any cmdlet, use the Get-Help cmdletname cmdlet.
get-help get-help
PS C:/> get-help get*
PS C:/> get-help getdrive -example
1.Retrieve an alphabetic listing of all currently defined aliases, and inspect the list for one assigned to either the Get-Help cmdlet or the key stroke combination gh. The command to do this is as follows:
get-alias |sort
2.After you have determined that there is no alias for the Get-Help cmdlet, and that none is assigned to the gh key stroke combination, review the syntax for the Set-Alias cmdlet. Use the -full argument to the Get-Help cmdlet. This is shown here:
get-help set-alias -full
3.Use the Set-Alias cmdlet to assign the gh key stroke combination to the Get-Help cmdlet. To do this, use the following command:
set-alias gh get-help
1.Change to the C:/ root directory by typing cd C:/ inside the PowerShell prompt:
Cd c:/
2.Obtain a listing of all the files in the C:/ root directory by using the dir command:
dir
3.Create a directory off the C:/ root directory by using the md command:
Md mytest
4.Obtain a listing of all files and folders off the root that begin with the letter m:
Dir m*
5.Change the working directory to the PowerShell working directory. You can do this by using the Set-Location command as follows:
Set-location $pshome
6.Obtain a listing of memory counters related to the available bytes by using the typeperf command. This command is shown here:
typeperf "/memory/available bytes"
7.After a few counters have been displayed in the PowerShell window, use the ctrl-c command to break the listing.
8.Display the current boot configuration by using the bootcfg command:
Bootcfg
9.Change the working directory back to the C:/Mytest directory you created earlier:
set-location c:/mytest
10.Create a file named Mytestfile.txt in the C:/Mytest directory. Use the fsutil utility, and make the file 1,000 bytes in size. To do this, use the following command:
fsutil file createnew mytestfile.txt 1000
11.Obtain a “directory listing” of all the files in the C:/Mytest directory by using the Get-ChildItem cmdlet. This is shown here:
get-childitem
12.Print out the current date by using the Get-Date cmdlet. This is shown here:
get-date
13.Clear the screen by using the cls command. This is shown here:
cls
14.Print out a listing of all the cmdlets built into Windows PowerShell. To do this, use the Get-Command cmdlet. This is shown here:
get-command
15.Use the Get-Command cmdlet to get the Get-Alias cmdlet. To do this, use the -name argument while supplying Get-Alias as the value for the argument. This is shown here:
get-command -name get-alias
16.This concludes the step-by-step exercise. Exit the Windows PowerShell by typing exit and pressing Enter.
get-help get-help -detailed
get-help get-help -full
get-help get-help -examples