Overview of Windows PowerShell 5.0

  • 11/2/2015

Exploring commands: Step-by-step exercises

In the following exercises, you’ll explore the use of command-line utilities in Windows PowerShell. You will find 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 | PowerShell. The Windows PowerShell prompt opens by default at the root of your user folder.
  2. Change to the root of C:\ by entering cd c:\ inside the Windows PowerShell prompt.

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

    dir
  4. Create a directory off the root of C:\ 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 Windows 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.exe command. This command is shown here.

    typeperf "\memory\available bytes"
  8. After a few counters have been displayed in the Windows PowerShell window, press Ctrl+C to break the listing.
  9. Display the current startup configuration by using the bcdedit command (note that you must run this command with admin rights).

    bcdedit
  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 the current date by using the Get-Date cmdlet.
  14. Clear the screen by using the cls command.
  15. Print 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 parameter while supplying Get-Alias as the value for the parameter. This is shown here.

    Get-Command -name Get-Alias

    This concludes the step-by-step exercise. Exit Windows PowerShell by entering 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 | PowerShell. The Windows PowerShell prompt opens by default at the root of your user 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 switch parameter, as follows.

    Get-Help Get-Help -detailed
  4. To retrieve technical information about the Get-Help cmdlet, use the -Full switch parameter. 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 switch parameter, 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 entering exit and pressing Enter.