hello
Google
Welcome to Carpe Diem: Flaphead@Home Sign in | Join | Help

Carpe Diem: Flaphead.com

Seize the Day

News


  • Add to Technorati Favorites <script type="text/javascript" src="http://technorati.com/embed/3ni3q36ikc.js"> </script>
    This information is provided "AS IS" with no warranties, and confers no rights. Also some of the information contains my views and thoughts.
    <script src="http://widgets.technorati.com/t.js" type="text/javascript" charset="UTF-8"></script>

    Add Me! - Search Engine Optimization

    I heart FeedBurner

Outputting Powershell Commands

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 (
http://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:
http://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: http://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

Posted: 31 August 2006 17:24 by Paul Flaherty
Filed under: ,

Comments

Lee said:

You might find it a bit easier to store your scripts in a 'Tools' or 'Scripts' directory, rather than the installation directory. Then, add that directory to your path.

PowerShell searches the path for scripts as well, so that lets you keep all of your scripts together, without having to worry about mucking around in the PowerShell installation directory.
# September 2, 2006 07:43

Brettjo :: Microsoft Exchange Messaging said:

I think the following post from Paul says it all really.
# September 4, 2006 11:07

Flaphead on TechNet said:

Originally Posted here: http://blogs.flaphead.dns2go.com/archive/2006/08/31/3538.aspx My buddy Brett...
# September 12, 2006 10:20

Flaphead on TechNet said:

Originally Posted here: http://blogs.flaphead.dns2go.com/archive/2006/08/31/3538.aspx My buddy Brett...
# September 12, 2006 10:20
New Comments to this post are disabled