MicrosoftВ® Windows PowerShell(TM) Step By Step (Step By Step (Microsoft))

As mentioned earlier, command-line utilities can be used directly within Windows PowerShell. The advantages of using command-line utilities in Windows PowerShell, as opposed to simply running them in the CMD interpreter, are the Windows PowerShell pipelining and formatting features. Additionally, if you have batch files or CMD files that already utilize existing command-line utilities, they can easily be modified to run within the Windows PowerShell environment. This command is in the  RunningIpconfigCommands.txt file.

Running ipconfig commands

  1. Start the Windows PowerShell by using Start | Run | Windows PowerShell. The PowerShell prompt will open by default at the root of your Documents And Settings.

  2. Enter the command ipconfig /all. This is shown here:

    PS C:\> ipconfig /all

  3. Pipe the result of ipconfig /all to a text file. This is illustrated here:

    PS C:\> ipconfig /all >ipconfig.txt

  4. Use Notepad to view the contents of the text file. This is shown here:

    PS C:\> notepad ipconfig.txt

Typing a single command into Windows PowerShell is useful, but at times you may need more than one command to provide troubleshooting information, or configuration details to assist with setup issues or performance problems. This is where Windows PowerShell really shines. In the past, one would have to either write a batch file or type the commands manually.

Note 

Netdiag.exe referenced in the  TroubleShoot.bat file is not part of the standard Windows install, but is a resource kit utility that can be downloaded from http://www.microsoft.com/downloads.

This is seen in the  TroubleShoot.bat script that follows.

 TroubleShoot.bat

ipconfig /all >C:\tshoot.txt route print >>C:\tshoot.txt netdiag /q >>C:\tshoot.txt net statistics workstation >>C:\tshoot.txt

Of course, if you typed the commands manually, then you had to wait for each command to complete before entering the subsequent command. In that case, it was always possible to lose your place in the command sequence, or to have to wait for the result of each command. The Windows PowerShell eliminates this problem. You can now enter multiple commands on a single line, and then leave the computer or perform other tasks while the computer produces the output. No batch file needs to be written to achieve this capability.

Tip 

Use multiple commands on a single Windows PowerShell line. Type each complete command, and then use a semicolon to separate each command.

The use of this procedure is seen in the Running multiple commands procedure. The command used in the procedure are in the  RunningMultipleCommands.txt file.

Running multiple commands

  1. Start the Windows PowerShell by using Start | Run | Windows PowerShell. The PowerShell prompt will open by default at the root of your Documents And Settings.

  2. Enter the ipconfig/all command. Pipe the output to a text file called Tshoot.txt by using the redirection arrow (>). This is the result:

    ipconfig /all >tshoot.txt

  3. On the same line, use a semicolon to separate the ipconfig/all command from the route print command. Append the output from the command to a text file called Tshoot.txt by using the redirect and append arrow (>>). The command to this point is shown as follows:

    ipconfig /all >tshoot.txt; route print >>tshoot.txt

  4. On the same line, use a semicolon to separate the route print command from the netdiag /q command. Append the output from the command to a text file called Tshoot.txt by using the redirect and append arrow. The command to this point is shown here:

    ipconfig /all >tshoot.txt; route print >>tshoot.txt; netdiag /q >>tshoot .txt

  5. On the same line, use a semicolon to separate the netdiag/q command from the net statistics workstation command. Append the output from the command to a text file called Tshoot.txt by using the redirect and append arrow. The completed command looks like the following:

    ipconfig /all >tshoot.txt; route print >>tshoot.txt; netdiag /q >>tshoot .txt; net statistics workstation >>tshoot.txt

Категории