Comparing ConfigMgr Date Formats in PowerShell

If you have worked with ConfigMgr much, you know that uses WMI to stores tons of information.  WMI uses the CIM_DATETIME format, which looks like this: yyyymmddHHMMSS.mmmmmmsUUU.  In order to work with this in PowerShell, you need to convert it into something that the Get-Date cmdlet can understand.  Here are two ways that you can accomplish this:

Using the ManagementDateTimeConverter Class:

get-date ([system.management.managementdatetimeconverter]::todatetime('20141004185400.000000+***'))

or by using the ConvertToDateTime() method:

([wmi]"").ConvertToDateTime('20141004185400.000000+***')

And here is an example for a required deployment policy comparing the EnforcementDeadline to the current date:

$EnforcementDate = Get-WmiObject -Namespace "root\ccm\Policy\Machine\RequestedConfig" -Class CCM_ApplicationCIAssignment | Where-Object { (($_.AssignmentName -eq 'My Application_Install') -and ($_.EnforcementDeadline -ne $null))}
$DeadlinePast = $EnforcementDate.ConvertToDateTime($y.EnforcementDeadline) -lt (Get-Date)

Originally posted on https://miketerrill.net/

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