There was a question on Technet forum a while ago, requesting a script to configure the “Automatically install or uninstall required software and restart the computer only outside of the specified business hours”. http://social.technet.microsoft.com/Forums/en-US/configmanagerapps/thread/08d2f8e9-feaf-4143-af56-7e97ef20267c/
Torsten Meringer, ConfigMgr MVP wrote a blog post and a script a while back on how to modify the Business Hours using a vbscript, it can be found here http://www.mssccmfaq.de/2012/03/26/software-center-business-hours-auslesen-setzen/
I used Torsten’s excellent script and modified it to change the “Automatically install or uninstall….” setting instead. I will post it here if anyone else need to configure that setting.
Here is a script to check what the setting is:
Set objUX = GetObject("winmgmts:\\.\root\ccm\ClientSDK:CCM_ClientUXSettings")
Set GBH = objUX.ExecMethod_("GetAutoInstallRequiredSoftwaretoNonBusinessHours")
WScript.echo "Automatically install or uninstall required software and restart the computer only outside of the specified business hours : " & GBH.AutomaticallyInstallSoftware
Here is a script to enable the “Automatically install or uninstall required software and restart the computer only outside of the specified business hours” setting.
Set objUX = GetObject("winmgmts:\\.\root\ccm\ClientSDK:CCM_ClientUXSettings")
Set inParam = objUX.Methods_.Item("SetAutoInstallRequiredSoftwaretoNonBusinessHours").inParameters.SpawnInstance_()
inParam.AutomaticallyInstallSoftware = "True"
Set result = objUX.ExecMethod_("SetAutoInstallRequiredSoftwaretoNonBusinessHours", inParam)
Thanks to Torsten who wrote the original script!!
Great job, now to translate it to powershell 🙂
Exactly what I needed, thanks a lot 🙂
$Return = Invoke-WmiMethod -Namespace “Root\ccm\ClientSDK” -Class CCM_ClientUXSettings -Name SetAutoInstallRequiredSoftwaretoNonBusinessHours -ArgumentList @($TRUE) -ComputerName $ComputerName -ErrorAction STOP
Discovery Script –
$cmClientUserSettings = [WmiClass]”\\.\ROOT\ccm\ClientSDK:CCM_ClientUXSettings”
$nonbusinessHours = $cmClientUserSettings.GetAutoInstallRequiredSoftwaretoNonBusinessHours()
Return $nonbusinessHours.AutomaticallyInstallSoftware
Remediation Script –
Invoke-WmiMethod -Namespace “Root\ccm\ClientSDK” -Class CCM_ClientUXSettings -Name SetAutoInstallRequiredSoftwaretoNonBusinessHours -ArgumentList @($TRUE)
This doesn’t work as a detection method in SCCM because no matter the return the application is detected I need something that will return true for detection and nothing if there is no detection as false becomes true when returned.