Convert standard Date/Time to a Configuration Manager Date/Time

This function allows you to convert the standard Date/Time as returned by the for example Get-Date function into a usable Date/Time object for Configuration Manager. This function is used in combination with others to define a Maintenance Window on a collection or can be used in other cases. The original function can be found on the blog of David O’Brien.

NOTE: By including the SYNOPSIS and other information you can use get-help on the function to find out what parameters you can specify or read what this function actually can be used for. I can highly recommended to always include this information in your PowerShell function(s) so that anybody can understand it.

Convert-NormalDateToConfigMgrDate Examples


Function Convert-NormalDateToConfigMgrDate
    Returns a Configuration Manager DateTime format converted from the supplied Date/Time
    This function converts a standard Date/Time to a Date/Time format that can be used within Configuration Manager.

    Convert-NormalDateToConfigMgrDate -StdDateTime (get-date)

    .PARAMETER StdDateTime
    This parameter is the default DateTime format to be converted
  Write-Verbose "Standard Date/Time                 : $StdDateTime"
  $ConfigMgrDateTime = [System.Management.ManagementDateTimeconverter]::ToDMTFDateTime($StdDateTime)
  Write-Verbose "ConfigMgr Date/Time                : $ConfigMgrDateTime"
  return $ConfigMgrDateTime
Posted in PowerShell, System Center Configuration Manager, WMI.