Overview of Windows PowerShell 3.0

  • 2/15/2013

Exploring commands: step-by-step exercises

In the following exercises, you’ll explore the use of command-line utilities in Windows PowerShell. You will see that it is as easy to use command-line utilities in Windows PowerShell as in the CMD interpreter; however, by using such commands in Windows PowerShell, you gain access to new levels of functionality.

Using command-line utilities

  1. Open Windows PowerShell by choosing Start | Run | Windows PowerShell. The PowerShell prompt will open by default at the root of your Documents folder.

  2. Change to the C:\root directory by typing cd c:\ inside the PowerShell prompt:

    cd c:\
  3. Obtain a listing of all the files in the C:\root directory by using the dir command:

    dir
  4. Create a directory off the C:\root directory by using the md command:

    md mytest
  5. Obtain a listing of all files and folders off the root that begin with the letter m:

    dir m*
  6. Change the working directory to the PowerShell working directory. You can do this by using the Set-Location command as follows:

    Set-Location $pshome
  7. 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"
  8. After a few counters have been displayed in the PowerShell window, press Ctrl+C to break the listing.

  9. Display the current boot configuration by using the bootcfg command (note that you must run this command with admin rights):

    bootcfg
  10. Change the working directory back to the C:\Mytest directory you created earlier:

    Set-Location c:\mytest
  11. 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
  12. Obtain a directory listing of all the files in the C:\Mytest directory by using the Get-ChildItem cmdlet.

  13. Print out the current date by using the Get-Date cmdlet.

  14. Clear the screen by using the cls command.

  15. Print out a listing of all the cmdlets built into Windows PowerShell. To do this, use the Get-Command cmdlet.

  16. 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 Windows PowerShell by typing exit and pressing Enter.

In the following exercise, you’ll use various help options to obtain assistance with various cmdlets.

Obtaining help

  1. Open Windows PowerShell by choosing Start | Run | Windows PowerShell. The PowerShell prompt will open by default at the root of your Documents folder.

  2. Use the Get-Help cmdlet to obtain help about the Get-Help cmdlet. Use the command Get-Help Get-Help as follows:

    Get-Help Get-Help
  3. To obtain detailed help about the Get-Help cmdlet, use the -detailed argument as follows:

    Get-Help Get-Help -detailed
  4. To retrieve technical information about the Get-Help cmdlet, use the -full argument. This is shown here:

    Get-Help Get-Help -full
  5. If you only want to obtain a listing of examples of command usage, use the -examples argument as follows:

    Get-Help Get-Help -examples
  6. Obtain a listing of all the informational help topics by using the Get-Help cmdlet and the about noun with the asterisk (*) wildcard operator. The code to do this is shown here:

    Get-Help about*
  7. Obtain a listing of all the help topics related to get cmdlets. To do this, use the Get-Help cmdlet, and specify the word get followed by the wildcard operator as follows:

    Get-Help get*
  8. Obtain a listing of all the help topics related to set cmdlets. To do this, use the Get-Help cmdlet, followed by the set verb, followed by the asterisk wildcard. This is shown here:

    Get-Help set*

    This concludes this exercise. Exit Windows PowerShell by typing exit and pressing Enter.