Monday, June 1, 2009

Input Box To Change SMS Site Name By Computer Name

Here is a little script that I put together by combining a few other scripts. When ran an Input box will pop up and ask for the computer name. It will then return the current Site name, then the new name that you specify by editing the file. If the computer is not on nothing will be returned.


Option Explicit
On Error Resume Next
Dim WSHShell, WSHNetwork, Input, smsClient, inparam, Newresult, Newsite, oCCMNamespace, strComputer, result

Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")

Input = InputBox("Enter the Computer name","SMS Site Code Fix")
strComputer = Input

'get the current site code
set oCCMNamespace = GetObject("winmgmts://" & strComputer & "/root/ccm")
Set smsClient = oCCMNamespace.Get("SMS_Client")
Set result = smsClient.ExecMethod_("GetAssignedSite")
wscript.echo strComputer & " Current Assigned Site is: " & result.sSiteCode

'Reassign the site code
Set inParam =smsClient.Methods_.Item("SetAssignedSite").inParameters.SpawnInstance_()
inParam.sSiteCode = "XYZ"
Set Newresult = smsClient.ExecMethod_("SetAssignedSite", inParam)
Set NewSite = smsClient.ExecMethod_("GetAssignedSite")
wscript.echo strComputer & " New Assigned Site is : " & NewSite.sSiteCode



Make sure to change the site code to your site code.
inParam.sSiteCode = "XYZ"

No comments:

Post a Comment