A question from one of my MVP friends: Do you have a script to change client site code? Someone assigned a wrong sitecode to some clients and need to change it.
This VBScript was developed to handle an entire office moving from one physical location to another, and clients required assignment to a different site.
Most of the scripts I reviewed simply force the site code. This script is designed to be a little more intelligent. It performs an auto discover to determine where the client should be assigned, then looks up the current assigned site. If these are different, assign it to the auto discovered site.
Use “smart” collections so you don’t inadvertently change a site code of a legitimate, roaming user.
VBScript below, watch the line wrap when copying.
' Created by S. Thompson ' Version 1.00 ' Function: Obtain current SMS site assignment and compare to "auto" discovered ' site. If these values are different, set client SMS site assignment ' to discovered site. Option Explicit dim oSMSClient dim strDiscoverSite dim strAssignedSite On Error Resume Next Set oSMSClient = CreateObject ("Microsoft.SMS.Client") If err.Number <> 0 then ' wscript.echo "Could not create SMS Client Object - quitting" Else strDiscoverSite = CallAutoDiscoverSite () strAssignedSite = CallGetAssignedSite () If strAssignedSite <> strDiscoverSite Then Call SetAssignedSite (strDiscoverSite) End If End If Set oSMSClient=nothing Function CallAutoDiscoverSite () dim strDiscoveredSite strDiscoveredSite = oSMSClient.AutoDiscoverSite If Len(strDiscoveredSite & "")>0 Then ' we have something Else strDiscoveredSite = "DiscoveredSiteNotFound" End If ' wscript.echo "Discovered Site is : '" & strDiscoveredSite & "'" CallAutoDiscoverSite = strDiscoveredSite End Function Function CallGetAssignedSite () dim strAssignedSite strAssignedSite = oSMSClient.GetAssignedSite If Len(strAssignedSite & "")>0 Then ' we have something Else strAssignedSite = "AssignedSiteNotFound" End If ' wscript.echo "Assigned Site is : '" & strAssignedSite & "'" CallGetAssignedSite = strAssignedSite End Function Sub SetAssignedSite (SiteCode) oSMSClient.SetAssignedSite SiteCode,0 End Sub
Pingback: Step-by-step SCCM 1511 Migration from SCCM 2012
Pingback: Obtain current SMS site assignment and compare to “auto” discovered ‘ site |