MicrosoftВ® Windows PowerShell(TM) Step By Step (Step By Step (Microsoft))
In this exercise, we explore the use of command-line utilities in Windows PowerShell. You will see that it is as easy to use command-line utilities in the Windows PowerShell as in the CMD interpreter; however, by using such commands in the Windows PowerShell, you gain access to new levels of functionality.
-
Start Windows PowerShell by using Start | Run | Windows PowerShell. The PowerShell prompt will open by default at the root of your Documents And Settings.
-
Change to the C:\ root directory by typing cd C:\ inside the PowerShell prompt:
Cd c:\
-
Obtain a listing of all the files in the C:\ root directory by using the dir command:
dir
-
Create a directory off the C:\ root directory by using the md command:
Md mytest
-
Obtain a listing of all files and folders off the root that begin with the letter m:
Dir m*
-
Change the working directory to the PowerShell working directory. You can do this by using the Set-Location command as follows:
Set-location $pshome
-
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"
-
After a few counters have been displayed in the PowerShell window, use the ctrl-c command to break the listing.
-
Display the current boot configuration by using the bootcfg command:
Bootcfg
-
Change the working directory back to the C:\Mytest directory you created earlier:
set-location c:\mytest
-
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
-
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
-
Print out the current date by using the Get-Date cmdlet. This is shown here:
get-date
-
Clear the screen by using the cls command. This is shown here:
cls
-
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
-
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
-
This concludes the step-by-step exercise. Exit the Windows PowerShell by typing exit and pressing Enter.
Категории