Some time ago, I wrote an article about reassigning an SMS client to another SMS site. Since this topic seems to crop up periodically on both the myITforum list and public newsgroups, it is worth mentioning here.
At the time this script was developed, we were closing a large office in one location and moving the clients to another physical location. This meant transitioning approximately 2,500 clients between buildings. We could have uninstalled the client first, however it seemed to make more sense to script a solution that would detect what was the current site code for the client, and what was the client's assigned site code. If these 2 values were different, reset the client to the discovered site.
This functionality has also proved useful for situations where SMS/ConfigMgr clients become orphaned. This script can be launched as a machine GPO, or sent as an advertisement.
* Note: probably the only "flaw" in this logic, if you have an active advertisement running, a roaming laptop could inadvertently be discovered/assigned to an incorrect site. This script could be tuned to detect and ignore laptop class computers.
' DiscoverSetAssignedSite.vbs
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