We Don’t Need No Stinkin’ Scripts…

By Jesse Hamrick • September 26th, 2007

Another reason to love PowerShell… the command line. We work directly with objects in the command shell; minimal code required. The days of writing VBScripts to pull system information is long gone. Still hanging on to VBScript, resistant to change, this article may just change your mind…

At a minimum, it takes only two words to pull the default WMI properties of a class using PowerShell:

  1. Get-WmiObject cmdlet.
  2. The WMI Class you wish to enumerate.

For example:

Get-WmiObject win32_LogicalDisk

PowerShell WMI Output

How sick is that?!?

How about getting the default properties of the computer system class:

Get-WmiObject win32_ComputerSystem

Let’s go a step further and list all the properties of the win32_ComputerSystem class using a regular expression:

Get-WmiObject win32_ComputerSystem | Format-List [a-z]*

Now let’s just get properties we are interested in. Choose any property you wish:

Get-WmiObject win32_ComputerSystem | Format-List Name,Domain,Manufacturer,Model,UserName

I know what you are thinking, this is great for gathering information from the local computer, how do we gather the same information from remote computers?

Introducing the greatest parameter of the all… (drum-roll please)……… -ComputerName!!!

Get-WmiObject win32_ComputerSystem -ComputerName TypeAComputerNameHere

Using the Format cmdlet let’s get all the properties from a remote Computer:

Get-WmiObject win32_ComputerSystem -ComputerName TypeAComputerNameHere | Format-List [a-z]*

So the next time the boss inquires about how much drive space is available on a server, don’t write a VBScript, just run the PowerShell commands above. What a time saver!!! Of course, if the boss wants the same report from multiple remote servers, time to write a “PowerShell” script…

Email This Post To A Friend Email This Post To A Friend

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • Digg
  • Furl
  • Reddit
  • Technorati
  • YahooMyWeb

Comments

By Trevor Sullivan on February 18th, 2008 at 10:23 am

Awesome! Now run that in WinPE for me.

Powershell is great, but it is limited by requiring a full running o/s to work. Even then, it won’t work on Windows 2008 Server Core …

 

Leave a Comment

« Organizing Script Code - Calling Scripts from Other Script Files | Home | “Let’s do the Time Zone Again…” »