Skip to content

Instantly share code, notes, and snippets.

@Nora-Ballard
Created February 15, 2014 13:34
Show Gist options
  • Save Nora-Ballard/9019401 to your computer and use it in GitHub Desktop.
Save Nora-Ballard/9019401 to your computer and use it in GitHub Desktop.
function Repair-SCCMHttpStatus($ComputerName,$DesiredHttpsState = 0x0000005f)
{
$WhatIf = $false
$HTTPSStates = @{
'0' = 'Mixed mode'
'31' = 'Native mode'
'63' = 'Native mode, CRL'
'95' = 'Native mode, FALLBACK'
'127' = 'Native mode, CRLANDFALLBACK'
}
# The 'HttpsState' registry value determines whether the
# SCCM Client uses Native (HTTPS) or Mixed (HTTP) communication.
#
$SCCMService = Get-Service -ComputerName $ComputerName -Name 'ccmexec' -ErrorAction SilentlyContinue
$OSArchitecture = (Get-WmiObject -ComputerName $ComputerName Win32_OperatingSystem).OSArchitecture
$Subkey = "SOFTWARE\\Microsoft\\CCM"
if ($OSArchitecture -eq '64-bit') { $Subkey = "SOFTWARE\\Wow6432Node\\Microsoft\\CCM" }
if ($SCCMService)
{
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computername )
$regKey = $reg.OpenSubKey($Subkey,$true)
$StartingHTTPSState = $regKey.GetValue('HttpsState')
# If the data of the 'HttpsState' value doesn't match the desired value, replace it.
if ($StartingHTTPSState -ne $DesiredHttpsState)
{
Write-Warning "SCCM Client on '$ComputerName' has invalid 'HttpsState ($StartingHTTPSState)'"
Write-Host "$(if ($WhatIf) { 'WHATIF: ' } else { '' })Performing operation 'SetValue=$DesiredHttpsState' on 'HttpsState'"
if (!$WhatIf) { $regKey.SetValue("HttpsState",$DesiredHttpsState,'DWORD') }
}
$FinalHTTPSState = $regKey.GetValue('HttpsState')
if (($FinalHTTPSState -ne $DesiredHttpsState) -and ($StartingHTTPSState -ne $Null))
{
Write-Warning "Failed to set 'HTTPSState($FinalHTTPSState)' to '$DesiredHttpsState'"
}
write-output $( [pscustomobject]@{'StartingValue'=$StartingHTTPSState; 'FinalValue'=$FinalHTTPSState} )
}
else
{
Write-Warning "SCCM Client is not installed on '$ComputerName'."
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment