Created
May 25, 2017 16:07
-
-
Save Darkbat91/3c5eed4344dc7eea674abddc1589c30a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Set-SCCMClientBusinessHours | |
{ | |
<# | |
.SYNOPSIS | |
Sets the Business Hours of the SCCM client | |
.DESCRIPTION | |
Sets the flag for rebooting inside or outside of business Hours, The Working Days, And the Start end end time in 24 hour format | |
.PARAMETER ComputerName | |
Name of computer to set the configuration on - Default is Localhost | |
.PARAMETER RebootOutsideBusinessHours | |
When this flag is set will tell the system to only reboot outside of the specified business hours - Default is to not set | |
.PARAMETER WorkDays | |
Default Value of 62 is M-F | |
Sunday 1 | |
Monday 2 | |
Tuesday 4 | |
Wednesday 8 | |
Thursday 16 | |
Friday 32 | |
Saturday 64 | |
.PARAMETER StartTime | |
Sets the Start of business hours - Default same as SCCM 0500 | |
.PARAMETER StartTime | |
Sets the End of business hours - Default same as SCCM 2200 | |
.EXAMPLE | |
Set-SCCMClientBusinessHours | |
Configures SCCM to | |
Reboot when necessary ignoring business hours | |
Set Business hours of M-F 0500-2200 | |
.NOTES | |
Author: MicahJ | |
Creation Date: 20170525 | |
Last Modified: 20170525 | |
Version: 1.0.0 | |
----------------------------------------------------------------------------------------------------------------- | |
CHANGELOG | |
----------------------------------------------------------------------------------------------------------------- | |
1.0.0 Initial Script | |
----------------------------------------------------------------------------------------------------------------- | |
Credit | |
----------------------------------------------------------------------------------------------------------------- | |
Weekday settings from | |
https://powersheller.wordpress.com/2012/11/20/sccm-2012-setting-software-center-business-hours-with-a-compliance-configuration-item/ | |
#> | |
param( | |
[Parameter(Mandatory=$false, | |
ValueFromPipeline=$True, | |
ValueFromPipelineByPropertyName=$true)] | |
[Alias('IPAddress','__Server','CN','Name')] | |
[string[]]$ComputerName=$env:COMPUTERNAME, | |
[switch]$RebootOutsideBusinessHours, | |
[parameter(Mandatory = $false)] | |
[int]$WorkingDays= 62, | |
[parameter(Mandatory = $false)] | |
[ValidateScript({$_ -gt 0 -and $_ -lt 23})] | |
[int]$StartTime= 5, | |
[parameter(Mandatory = $false)] | |
[ValidateScript({$_ -gt 0 -and $_ -lt 23})] | |
[int]$EndTime= 22 | |
) | |
PROCESS | |
{ | |
Foreach($computer in $ComputerName) | |
{ | |
# Get WMI Object | |
$CCM = Get-WmiObject -Namespace root\ccm\ClientSDK -Class CCM_ClientUXSettings -List -ComputerName $computer | |
if($ccm.SetAutoInstallRequiredSoftwaretoNonBusinessHours($RebootOutsideBusinessHours.IsPresent).returnValue -eq 0) | |
{ | |
#We were successful! | |
} | |
else | |
{ | |
Write-Warning "$computer Failed Specified Reboot" | |
} | |
if($CCM.SetBusinessHours($workingDays, $starttime, $endtime).returnValue -eq 0) | |
{ | |
#Do nothing it was all successful | |
} | |
else | |
{ | |
Write-Warning "$computer Failed Business Hours" | |
} | |
} # End Foreach computername | |
}# End Process | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment