Converting to/from WMI Date Time

You will find many posts for how to convert a wmi date-time string to a human-friendly date time here’s one example from Don Jones.

First, here’s an example of the wmi date-time string:

Get-WmiObject -class Win32_OperatingSystem  | select __Server, LastBootUpTime

The value for LastBootUpTime will look something like this: 20120718141700.473048-300. This output is very handy for alpha-sort, by the way…
And Here’s Don’s code:

Get-WmiObject -class Win32_OperatingSystem | Select-Object __SERVER,@{label='LastRestart';expression={$_.ConvertToDateTime($_.LastBootUpTime)}}

Notice how Don elegantly converts the string on the fly with the label and expression arguments.

Now here’s an example of using a COM object to convert the current date time to a wmi date-time string.

$wmidate = new-object -com Wbemscripting.swbemdatetime
$date = get-date -format g

Not nearly as elegant, but it gets the job done. When you create objects in ConfigMgr that require a date-time field, you will usually enter a wmi date-time string.


Happy Scripting!




How To: List Task Sequence Environment Variables and Values

(another encore presentation from my old blog site…)

From the TechNet forums, this is an example for how to display Task Sequence Environment Variables and Values using VBScript:

Set oTSEnv = CreateObject(“Microsoft.SMS.TSEnvironment”)
For Each oVar In oTSEnv.GetVariables
WScript.Echo oVar & “=” & oTSEnv(oVar)

You could save those two lines of code to “ShowTSVars.vbs”, and then when you want, simply run “cscript //nologo ShowTSVars.vbs >vars.txt” to write all variables to vars.txt.