How to find what you CAN look for – a few tips
One of the stumbling blocks I personally ran into in Powershell was a actually a simple one to solve but I thought I might share it anyhow.
How do I go about finding what I can pull and use?
You already know about the GET-MEMBER commandlet. That will show you all the available properties of the Objects.
But sometimes “GET-MEMBER” isn’t enough. I mean in all fairness it’s gets you what you need but I found (Very often, especially with Exchange and Active Directory) it’s a matter of seeing what particular field you can pull up and if the CONTENT of that field meets your needs. And this trick is good with pretty much every Powershell command-let I’ve run across.
It’s the one that opened up my eyes.
With the Quest Active Roles Commandlets loaded fire up the following command (This is a free Powershell Addon from Quest Software that allows you to effectively work with Active Directory from Powershell)
Now that’s going to dump a list of ALL Active Directory users. But we all know, Active Directory has a LOT more than just Usernames. And to find out WHAT was available, Just pipe that into a VERY powerful and oh so handy commandlet “EXPORT-CSV”
EXPORT-CSV is pretty much what it says it is. It takes the Information you’re giving it (even stuff you can’t visibly see on the screen, like OTHER objects) and EXPORT’s that to a CSV (Comma Separated Value) file. And the way to use it is easy too. EXPORT-CSV NameOfFile.CSV (And if you’re wondering, yes there is also an IMPORT-CSV to Read back and send in. But that’s another time.
Now I have Excel for viewing this but any spreadsheet application out there will do fine to open up a CSV file.
And of course give it a location to dump it to. I like to have a little temporary folder off the root for Powershell. Mostly because I hate typing and I don’t want to wreck the NTFS permissions on the Root of C just to dump a simple CSV file. So in this case I have a folder called C:\ENERGIZED to dump my Powershell info into, or to test scripts or whatever.
GET-QADUSER | EXPORT-CSV C:\ENERGIZED\LISTOFAD.CSV
Once you open up this file you’ll see a series of columns with headers. Those columns are ALL the available objects being piped out. So if you remember a previous post I had about pulling a list of users from the data they were created, here’s where I got the information. I went into Active Directory and looked to see (Under the Advanced View) if certain information was available. Then I compared it with this output list (and checked the headers)
Now there is a LITTLE bit of guessing but not a lot. You can usually compare the header with the output under it to see if it meets your needs.
The other thing you can do with making GET-MEMBER more useful is to change it’s output. One of the things I found maddening was running a “GET-MEMBER” on the output only to find the lines cut off. This mostly happens when it lists a METHOD.
But the information is always there.
So another trick that’s good and handy is running your output through a FORMAT-LIST Commandlet.
GET-QADUSER | GET-MEMBER | FORMAT-LIST
Will show me that view in a lot greater detail. You have to scroll up and down the Powershell window but it’s all there.
But again. What you’ll find in Powershell is there is a lot you can work with. Sometimes it’s just a matter finding what you can get.
The Energized Tech
”……It’s so Easy and It’s Free, Download it now it’ll take no time….” "(Highway to Powershell)