I came up with a nice PowerShell script to manage our monthly maintenance windows in Configuration Manager based on MS Patch Tuesday + Offset. Create, Update and Clean up options. The script works beautifully when run interactively as an administrator. However, when run as a scheduled task or Configuration Item (intended purpose) it fails. I ran an interactive PowerShell session as System by using psexec.exe, the script successfully maps the PSDrive and imports the module but then all of the cmdlets fail with the same error.
New-CMSchedule : Value cannot be null. Parameter name: key
Get-CMCollection : Value cannot be null. Parameter name: key
Get-CMMaintenanceWindow : Value cannot be null. Parameter name: key
[Error: New-CMSchedule : Value cannot be null. Parameter name: key][1] [1]: https://i.stack.imgur.com/AEM2l.png
Since none of the cmdlets have a key parameter I believe the error is referring to this in the stack trace 'at System.Collections.Concurrent.ConcurrentDictionary`2.TryGetValue(TKey key, TValue& value)'
Does anyone know if there is a workaround I am missing, or is this just a limitation of how the module is written? Thanks in advance