04.07.2013 Views

Windows PowerShell 3.0 Step by Step - Cdn.oreilly.com - O'Reilly

Windows PowerShell 3.0 Step by Step - Cdn.oreilly.com - O'Reilly

Windows PowerShell 3.0 Step by Step - Cdn.oreilly.com - O'Reilly

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

tip Use multiple <strong>com</strong>mands on a single <strong>Windows</strong> <strong>PowerShell</strong> line. Type each <strong>com</strong>plete<br />

<strong>com</strong>mand, and then use a semicolon to separate each <strong>com</strong>mand.<br />

The following exercise describes how to run multiple <strong>com</strong>mands. The <strong>com</strong>mands used in the procedure<br />

are in the RunningMultipleCommands.txt file.<br />

running multiple <strong>com</strong>mands<br />

1. Open <strong>Windows</strong> <strong>PowerShell</strong> <strong>by</strong> choosing Start | Run | <strong>Windows</strong> <strong>PowerShell</strong>. The <strong>PowerShell</strong><br />

prompt will open <strong>by</strong> default at the root of your Documents And Settings folder.<br />

2. Enter the ipconfig /all <strong>com</strong>mand. Pipe the output to a text file called Tshoot.txt <strong>by</strong> using the<br />

redirection arrow (>). This is the result:<br />

ipconfig /all >tshoot.txt<br />

3. On the same line, use a semicolon to separate the ipconfig /all <strong>com</strong>mand from the route print<br />

<strong>com</strong>mand. Append the output from the <strong>com</strong>mand to a text file called Tshoot.txt <strong>by</strong> using the<br />

redirect-and-append arrow (>>). Here is the <strong>com</strong>mand so far:<br />

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

4. On the same line, use a semicolon to separate the route print <strong>com</strong>mand from the hostname<br />

<strong>com</strong>mand. Append the output from the <strong>com</strong>mand to a text file called Tshoot.txt <strong>by</strong> using the<br />

redirect-and-append arrow. The <strong>com</strong>mand up to this point is shown here:<br />

ipconfig /all >tshoot.txt; route print >>tshoot.txt; hostname >>tshoot<br />

.txt<br />

5. On the same line, use a semicolon to separate the hostname <strong>com</strong>mand from the net statistics<br />

workstation <strong>com</strong>mand. Append the output from the <strong>com</strong>mand to a text file called Tshoot.txt<br />

<strong>by</strong> using the redirect-and-append arrow. The <strong>com</strong>pleted <strong>com</strong>mand looks like the following:<br />

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

.txt; net statistics workstation >>tshoot.txt<br />

Security issues with <strong>Windows</strong> <strong>PowerShell</strong><br />

As with any tool as versatile as <strong>Windows</strong> <strong>PowerShell</strong>, there are bound to be some security concerns.<br />

Security, however, was one of the design goals in the development of <strong>Windows</strong> <strong>PowerShell</strong>.<br />

When you launch <strong>Windows</strong> <strong>PowerShell</strong>, it opens in your Documents folder; this ensures you are in<br />

a directory where you will have permission to perform certain actions and activities. This is far safer<br />

than opening at the root of the drive, or even opening in system root.<br />

6 <strong>Windows</strong> <strong>PowerShell</strong> 3 <strong>Step</strong> <strong>by</strong> <strong>Step</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!