?
Solved

PowerShell "Get-Command | Out-GridView" next steps?

Posted on 2011-05-05
8
Medium Priority
?
3,330 Views
Last Modified: 2012-05-11
When I run the powershell command:

PS> get-command | out-gridview

I get a nice graphical window pop up that has everything neatly formatted that I can scroll through and read about each command.  I want this nice and neat detailed information in Excel so I can change fonts, print it, use other formatting, etc.  I've been trying to find this solution all day, but cannot.  I'm new to PowerShell, so I don't know what I need to do to get this information into Excel so I can "do stuff" with it there.  I've tried some things like:

PS> get-command | format-list * | Export-csv output.csv
or
PS> get-command | format-list * | Out-File output.txt

I was not able to utilize either one to get all of the data nicely formatted like it is in GridView.  Excel 2003 kept combining things wrong and it was a mess. ><

How do I get the output from "Get-Command | Out-GridView" into another application so I can "do more stuff" with it?  (print, format, sort, etc.)  I'm going to need to know how to do that because I plan to use PowerShell to pull a lot of different kind of information in our system and be able to put them in sortable, printable, formattable formats (like Excel).  Like right now we need to get the information given by:

PS> dir | get-acl | out-gridview

into something more portable like an excel file.

Thanks.
0
Comment
Question by:UncleN00b
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 18

Accepted Solution

by:
Learnctx earned 1000 total points
ID: 35703041
Don't use Format-List and use the NoTypeInformation switch.
Get-Command | Export-Csv output.csv -NoTypeInformation

Open in new window

The same goes for your second command.
Get-ChildItem | Get-Acl | Export-Csv output.csv -NoTypeInformation

Open in new window

See how that goes.
0
 
LVL 18

Expert Comment

by:Learnctx
ID: 35703087
Forgot to add, you can use Select-Object * instead of Format-List * if you want to return all the properties, etc.
0
 
LVL 16

Expert Comment

by:Postmaster
ID: 35703360
Another variation is to use Format-Table " | ft"

Also LDAP queries are nice once you get the hang of them.

LDIFDE -f c:\output_file.txt -r "(displayname=*smith*) -l "displayname,mail"
gives text output

CSVDE -f c:\output_file.csv -r "(displayname=*smith*) -l "displayname,mail"
gives CSV output

Thes are run from a normal command prompt.
More info at
http://technet.microsoft.com/en-us/library/cc731033(WS.10).aspx
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

Author Comment

by:UncleN00b
ID: 35707582
So instead of:
Get-Command | Out-Gridview

Open in new window

Do:
Get-Command | Export-Csv output.csv -NoTypeInformation

Open in new window

Hey, that worked perfectly!  Thank you!

I also want to achieve the same result in adapting
dir | Get-Acl | Out-Gridview

Open in new window

so I tried:
dir | Get-Acl | Export-Csv output.csv -NoTypeInformation

Open in new window

But it doesn't list all of the folder permissions on each folder like gridview did. :(
Why doesn't that give me the same "gridview-esque" kind of csv output i'm looking for like the Get-Command example did?
0
 

Author Comment

by:UncleN00b
ID: 35707754
I should clarify a bit more.

dir | Get-Acl | Out-Gridview

Open in new window

This produces a column labeled Access in the GridView window.  This lists all accounts that have any access defined on each folder and file.  Try it and see what I mean if you can.  I'll attach a screenshot.

 outgridview
0
 
LVL 71

Assisted Solution

by:Chris Dent
Chris Dent earned 1000 total points
ID: 35708489
Out-GridView is sneaky, it inherits the formatting definitions in the same way that Format-Table does. Those formatting definitions are, in a number of cases very misleading. Get-Acl is one of the "best" examples of that, it tags columns in Format-Table / Out-GridView with one thing, and actually displays an entirely different field.

Access, or at least the one you want, is held in a property called AccessToString. So the fields Out-GridView is showing are:
dir | Get-Acl | Select-Object PSChildName, Owner, AccessToString | Export-Csv out.csv

Open in new window

Oh and, just in case, Path is actually PSChildName, the real property called Path holds something completely different.

Then if you open that up in Excel you'll have to resize the column height to see all the values.

Chris
0
 

Author Comment

by:UncleN00b
ID: 35709281
That's perfect, thank you Chris!

And thank you again Learnctx!

As I go, I'll utilize Select-Object when creating a csv to be sure I get the types of information I need.
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 35709339
Learnctx's tip about Select-Object * is a really good one. It'll drop off all the obscure formatting and give you access to the real and complete list of properties. I often use Format-List * in the console for exploration, but not for final output.

There's also Get-Member which tells you more still but may take a bit more work to interpret.

In this case, the real version of the Access property is an array which contains the full access control list (not just a text summary as AccessToString shows).

Chris
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question