Quantcast
Channel: ConfigMgr – Mike's Tech Blog
Viewing all articles
Browse latest Browse all 78

Comparing ConfigMgr Date Formats in PowerShell

$
0
0

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 http://miketerrill.net/



Viewing all articles
Browse latest Browse all 78

Trending Articles