Поделиться через


Outputting Powershell Commands

Originally Posted here: https://blogs.flaphead.dns2go.com/archive/2006/08/31/3538.aspx


My buddy Brett asked me about this a few weeks ago and I never managed to get to him .. sorry buddy! So I decided to come back to everyone.

After playing with powershell a bit you get an idea of the power you have. So something that really makes it rock is the ability to pipe the output from a command to another command.

So I have a few to show you.

OUT-HTML
This will Pipe the output of command to a HTML table. You can get the source from Viveks web site (https://www.viveksharma.com/techlog/attache/out-html.web.txt)

Okay so:
PS > dir *.ps1

    Directory: Microsoft.PowerShell.Core\FileSystem::C:\

Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 31/08/2006 14:32 2037 format-hex.ps1
-a--- 24/07/2006 22:16 1713 For_Loops.ps1

Becomes (this is just a snip):

PS > dir *.ps1 | out-html

PS C:\_> dir *.ps1 | out-html
<style>
<!--
body { font: Helvetica }
table { font: 12pt Helvetica; border: 0px}
td { border: 1px solid lightgray; padding-left: 15px; padding-right: 15px }
p.header { font: 16pt Helvetica; color: DarkBlue }
p.normal { font: 14pt Helvetica; }
-->
</style>
</head>
<body>
<p class="header" align='center'><strong>Output Generated by paulfl at: 31/08/2006 15:56:02 on machine paulfl-m400 </strong></p>
<p class='normal' align='center'><strong>Command line:</strong> dir *.ps1 | out-html</p><br>
<table border="1" cellpadding="0" cellspacing="0" align="center">
<tr>
<td align="center" style="background-color: darkblue"><p class="table" style="color: white"><b>PSChildName</b></p></td>
<td align="center" style="background-color: darkblue"><p class="table" style="color: white"><b>PSDrive</b></p></td>
<td align="center" style="background-color: darkblue"><p class="table" style="color: white"><b>PSIsContainer</b></p></td>
<td align="center" style="background-color: darkblue"><p class="table" style="color: white"><b>PSParentPath</b></p></td>
<td align="center" style="background-color: darkblue"><p class="table" style="color: white"><b>PSPath</b></p></td>

OUT-IE
This is cool, as it lets you output the command to an IE window. You can see where I am coming from, can’t you. Combine out-html and out-ie and you get a nice table in a new IE window. out-ie is quite a simple bit of code, and vivek details it here: https://www.viveksharma.com/techlog/2006/05/09/technet-webcast-follow-up-out-html-out-ie/

so when I do the following, it list out a dir *.ps1 into a new IE window in a formatted table. How cool is that!

PS > dir *.ps1 | out-html | out-ie

OUT-GRID
This is quite cool. I found the source here: https://abhishek225.spaces.live.com/PersonalSpace.aspx?_c11_blogpart_blogpart=blogview&_c=blogpart&partqs=amonth%3D5%26ayear%3D2006, right down the bottom of the page.

So the following command will open up a data grid application and display the results!

PS > dir *.ps1 | out-grid

AND FINALLY
Once you have collated all the out– you want, you should copy them in to C:\Program Files\Windows PowerShell\v1.0 That way you can use them at any PS> prompt!

I have seen a few more too, but I can’t find them on the web, so if anyone can find: out-chart and out-email let me know and I will post them up