W2KSG: Operating System Info

Progressing through the guide we have a variation on our previous script – this time we want to retrieve information about the operating system

Listing 6.7

Get-WmiObject -Class Win32_OperatingSystem | Select Name, Caption, CurrentTimeZone,

@{Name=’LastBootUpTime'; Expression={$_.ConvertToDateTime($_.LastBootUpTime)}},

@{Name=’LocalDateTime'; Expression={$_.ConvertToDateTime($_.LocalDateTime)}},

Locale, Manufacturer, OSType, Version, ServicePackMajorVersion, ServicePackMinorVersion, WindowsDirectory

We use Win32_OperatingSystem in Get-WmiObject and then a select as normal.  Most of the properties are straightforward but the LastBootUpTime and the LocalDateTime are held in WMI’s format rather than a more readable form. 

We can use a calculated expression as shown to perform the conversion.  Using a variation of a hashtable we define a name for the field and use a script block to define the expression used to calculate the value. As the object is coming down the pipeline we can use $_ to represent that object.


Share this post :


About these ads
This entry was posted in PowerShell and WMI. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s