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.
Code:
Function Convert-NormalDateToConfigMgrDate { <# .SYNOPSIS Returns a Configuration Manager DateTime format converted from the supplied Date/Time .DESCRIPTION This function converts a standard Date/Time to a Date/Time format that can be used within Configuration Manager. .EXAMPLE Convert-NormalDateToConfigMgrDate -StdDateTime (get-date) .PARAMETER StdDateTime This parameter is the default DateTime format to be converted #> Param( [Parameter(Mandatory=$true,ValueFromPipeline=$true)] [string]$StdDateTime ) Write-Verbose "Standard Date/Time : $StdDateTime" $ConfigMgrDateTime = [System.Management.ManagementDateTimeconverter]::ToDMTFDateTime($StdDateTime) Write-Verbose "ConfigMgr Date/Time : $ConfigMgrDateTime" return $ConfigMgrDateTime }
Pingback: Create a Schedule Token for usage within SCCM – Bits and bytes from a Windows Engineer
Pingback: Set Maintenance Window on an SCCM Collection using PowerShell – Bits and bytes from a Windows Engineer
Pingback: Function to create and set a Maintenance Window on a specified SCCM Collection – Bits and bytes from a Windows Engineer