Setting SCCM Maintenance Windows based on Patch Tuesday with Powershell
Ioan Popovici
21

Hi Loan, I am getting a myriad of errors, could you kindly assist?

Removing maintenance windows from: MWU-SU-Servers-Week1_Day3A
MWA.NR.2017.August.09.21:00–3:00 — Removed!
MWA.NR.2017.October.11.21:00–3:00 — Removed!
Setting maintenance windows on: MWU-SU-Servers-Week1_Day3A
MWA.NR.2017.August.09.21:00–3:00 — Set!
Get-Date : Cannot bind parameter ‘Date’. Cannot convert value “13/09/2017 21:00” to type “System.DateTime”. Error: “String was not recognized as a valid DateTime.”
At D:\Scripts\Set-MaintenanceWindows.ps1:364 char:62
+ $MWStartTime = Get-Date -Format ‘dd/MM/yyyy HH:mm’ -Date ($PatchDay+’ ‘+$Sta …
+ ~~~~~~~~~~~~~~~~~~~
 + CategoryInfo : InvalidArgument: (:) [Get-Date], ParameterBindingException
 + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetDateCommand
 
Get-Date : Cannot bind parameter ‘Date’. Cannot convert value “13/09/2017 3:00” to type “System.DateTime”. Error: “String was not recognized as a valid DateTime.”
At D:\Scripts\Set-MaintenanceWindows.ps1:365 char:61
+ $MWStopTime = Get-Date -Format ‘dd/MM/yyyy HH:mm’ -Date ($PatchDay+’ ‘+$Stop …
+ ~~~~~~~~~~~~~~~~~~~~
 + CategoryInfo : InvalidArgument: (:) [Get-Date], ParameterBindingException
 + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetDateCommand
 
New-CMSchedule : Cannot bind parameter ‘Start’ to the target. Exception setting “Start”: “Object reference not set to an instance of an object.”
At D:\Scripts\Set-MaintenanceWindows.ps1:368 char:41
+ $MWSchedule = New-CMSchedule -Start $MWStartTime -End $MWStopTime -NonRecurr …
+ ~~~~~~~~~~~~
 + CategoryInfo : WriteError: (:) [New-CMSchedule], ParameterBindingException
 + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.ConfigurationManagement.Cmdlets.Common.Schedule.NewScheduleCommand
 
Get-Date : Cannot bind parameter ‘Date’ to the target. Exception setting “Date”: “Object reference not set to an instance of an object.”
At D:\Scripts\Set-MaintenanceWindows.ps1:376 char:59
+ $MWName = $MWType+’.NR.’+(Get-Date -Uformat %Y.%B.%d $MWStartTime)+’.’+$Sta …
+ ~~~~~~~~~~~~
 + CategoryInfo : WriteError: (:) [Get-Date], ParameterBindingException
 + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.GetDateCommand

Setting on MWU-SU-Servers-Week1_Day3A — Failed!
System.Management.Automation.ParameterBindingValidationException: Cannot bind argument to parameter ‘Schedule’ because it is null.
 at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
 at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
 at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
 at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
MWA.NR.2017.October.11.21:00–3:00 — Set!
Get-Date : Cannot bind parameter ‘Date’. Cannot convert value “15/11/2017 21:00” to type “System.DateTime”. Error: “String was not recognized as a valid DateTime.”
At D:\Scripts\Set-MaintenanceWindows.ps1:364 char:62
+ $MWStartTime = Get-Date -Format ‘dd/MM/yyyy HH:mm’ -Date ($PatchDay+’ ‘+$Sta …
+ ~~~~~~~~~~~~~~~~~~~
 + CategoryInfo : InvalidArgument: (:) [Get-Date], ParameterBindingException
 + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetDateCommand
 
Get-Date : Cannot bind parameter ‘Date’. Cannot convert value “15/11/2017 3:00” to type “System.DateTime”. Error: “String was not recognized as a valid DateTime.”
At D:\Scripts\Set-MaintenanceWindows.ps1:365 char:61
+ $MWStopTime = Get-Date -Format ‘dd/MM/yyyy HH:mm’ -Date ($PatchDay+’ ‘+$Stop …
+ ~~~~~~~~~~~~~~~~~~~~
 + CategoryInfo : InvalidArgument: (:) [Get-Date], ParameterBindingException
 + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetDateCommand
 
New-CMSchedule : Cannot bind parameter ‘Start’ to the target. Exception setting “Start”: “Object reference not set to an instance of an object.”
At D:\Scripts\Set-MaintenanceWindows.ps1:368 char:41
+ $MWSchedule = New-CMSchedule -Start $MWStartTime -End $MWStopTime -NonRecurr …
+ ~~~~~~~~~~~~
 + CategoryInfo : WriteError: (:) [New-CMSchedule], ParameterBindingException
 + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.ConfigurationManagement.Cmdlets.Common.Schedule.NewScheduleCommand
 
Get-Date : Cannot bind parameter ‘Date’ to the target. Exception setting “Date”: “Object reference not set to an instance of an object.”
At D:\Scripts\Set-MaintenanceWindows.ps1:376 char:59
+ $MWName = $MWType+’.NR.’+(Get-Date -Uformat %Y.%B.%d $MWStartTime)+’.’+$Sta …
+ ~~~~~~~~~~~~
 + CategoryInfo : WriteError: (:) [Get-Date], ParameterBindingException
 + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.GetDateCommand

Setting on MWU-SU-Servers-Week1_Day3A — Failed!
System.Management.Automation.ParameterBindingValidationException: Cannot bind argument to parameter ‘Schedule’ because it is null.
 at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
 at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
 at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
 at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
Get-Date : Cannot bind parameter ‘Date’. Cannot convert value “13/12/2017 21:00” to type “System.DateTime”. Error: “String was not recognized as a valid DateTime.”
At D:\Scripts\Set-MaintenanceWindows.ps1:364 char:62
+ $MWStartTime = Get-Date -Format ‘dd/MM/yyyy HH:mm’ -Date ($PatchDay+’ ‘+$Sta …
+ ~~~~~~~~~~~~~~~~~~~
 + CategoryInfo : InvalidArgument: (:) [Get-Date], ParameterBindingException
 + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetDateCommand
 
Get-Date : Cannot bind parameter ‘Date’. Cannot convert value “13/12/2017 3:00” to type “System.DateTime”. Error: “String was not recognized as a valid DateTime.”
At D:\Scripts\Set-MaintenanceWindows.ps1:365 char:61
+ $MWStopTime = Get-Date -Format ‘dd/MM/yyyy HH:mm’ -Date ($PatchDay+’ ‘+$Stop …
+ ~~~~~~~~~~~~~~~~~~~~
 + CategoryInfo : InvalidArgument: (:) [Get-Date], ParameterBindingException
 + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.GetDateCommand
 
New-CMSchedule : Cannot bind parameter ‘Start’ to the target. Exception setting “Start”: “Object reference not set to an instance of an object.”
At D:\Scripts\Set-MaintenanceWindows.ps1:368 char:41
+ $MWSchedule = New-CMSchedule -Start $MWStartTime -End $MWStopTime -NonRecurr …
+ ~~~~~~~~~~~~
 + CategoryInfo : WriteError: (:) [New-CMSchedule], ParameterBindingException
 + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.ConfigurationManagement.Cmdlets.Common.Schedule.NewScheduleCommand
 
Get-Date : Cannot bind parameter ‘Date’ to the target. Exception setting “Date”: “Object reference not set to an instance of an object.”
At D:\Scripts\Set-MaintenanceWindows.ps1:376 char:59
+ $MWName = $MWType+’.NR.’+(Get-Date -Uformat %Y.%B.%d $MWStartTime)+’.’+$Sta …
+ ~~~~~~~~~~~~
 + CategoryInfo : WriteError: (:) [Get-Date], ParameterBindingException
 + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.GetDateCommand

Setting on MWU-SU-Servers-Week1_Day3A — Failed!
System.Management.Automation.ParameterBindingValidationException: Cannot bind argument to parameter ‘Schedule’ because it is null.
 at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
 at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
 at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
 at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

Listing all maintenance windows for: MWU-SU-Servers-Week1_Day3A 
 MWA.NR.2017.August.09.21:00–3:00
 MWA.NR.2017.October.11.21:00–3:00

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.