Thursday, 17 May 2012

SCCM - ClientAgent - Check Site Assignment

This script subroutine will quickly check the SMSAgent(ccmexec.exe) site assignment to ensure it is assigned to the correct SiteCode. This version is written for a multi-hierarchy site configuration. Modify/extend as required.

Sub CheckSite()
On Error Resume Next


        wscript.echo "Checking site assignment"
Dim oSMSClient, Site, objSysInfo, domain, strSiteCode
Set objSysInfo = CreateObject("ADSystemInfo")
domain = ucase(objSysInfo.DomainDNSName)
Set objSysInfo = Nothing
If Len(domain) < 0 Then
            domain = GetDomain
End If 
wscript.echo "Computer Domain: " & domain 
Set oSMSClient = CreateObject("Microsoft.SMS.Client")
If Err.Number <> 0 Then
strMsg = "SMSAgent is not installed correctly or not running." & vbCrLf & _
"Object Microsoft.SMS.Client does not exist"
wscript.MsgBox(strMsg)
Err.Clear
Exit Sub
End If
Site = ucase(oSMSClient.GetAssignedSite)
If Len(Site) < 1 Then
wscript.echo "The machine is not assigned to a valid sitecode"
                strSiteCode = FindSiteCode(domain)
wscript.echo "Should be set to " & strSiteCode
If strSiteCode = "999" Then
strMsg = "Site code could not be found correctly for domain"
                        wscript.msgbox(strMsg)
Exit Sub
End If
oSMSClient.SetAssignedSite(strSiteCode)
If Err.Number <> 0 Then
strMsg "Site reassign failed with error: " & Err.Number
wscript.msgbox(strMsg)
Err.Clear
Else
wscript.echo "Site reassignment successful"
End If
Else
  wscript.echo "Site: " & Site
End If
  mgmt =  oSMSClient.GetCurrentManagementPoint
wscript.echo "Mgmt Point: " & mgmt
Set oSMSClient = Nothing
End Sub
Function FindSiteCode(dom)
On Error Resume Next
Dim FQDN
FQDN = ".blah.com"
Select Case dom
Case "0" & FQDN
FindSiteCode="000"
Case "1" & FQDN
FindSiteCode="001"
Case "2" & FQDN
FindSiteCode="002"
Case "3" & FQDN
FindSiteCode="003"
Case "4" & FQDN
FindSiteCode="004"
Case "5" & FQDN
FindSiteCode="005"
Case "6" & FQDN
FindSiteCode="006"
Case "7" & FQDN
FindSiteCode="007"
Case "8" & FQDN
FindSiteCode="008"
Case "9" & FQDN
FindSiteCode="009"
Case "10" & FQDN
FindSiteCode="010"
Case Else
FindSiteCode="999"
' site cannot be found for the domain
  End Select
End Function

No comments:

Post a Comment