Script for site-code re-assignment
Hi All,
I have a script for re-assigning the site code for a client.
'replace with your Site Code
sSiteCode = "NEWSITECODE"
Dim WSHShell
Dim objNTInfo
Dim GetComputerName
Set objNTInfo = CreateObject("WinNTSystemInfo")
sMachine = lcase(objNTInfo.ComputerName)
Set WSHShell = WScript.CreateObject("WScript.Shell")
set oCCMNamespace = GetObject("winmgmts://" & sMachine & "/root/ccm")
Set oInstance = oCCMNamespace.Get("SMS_Client")
set oParams = oInstance.Methods_("SetAssignedSite").inParameters.SpawnInstance_()
oParams.sSiteCode = sSiteCode
oCCMNamespace.ExecMethod "SMS_Client", "SetAssignedSite", oParams
I have tried it and it actually changes the site code. But after running the script and after the process of changing the site code. I am not able to push any software's to that client.
can someone shed some light on this?
Thanks
Sameer
October 15th, 2010 4:23pm
can someone shed some light on this?
Not without further information.
What does not work? What are the symptoms or errors?
I'd check locationservices, clientlocation, clientidmanagerstartup and ccmexec.log first.
Free Windows Admin Tool Kit Click here and download it now
October 15th, 2010 4:51pm
let me check that...i will post the findings.
thanks
October 15th, 2010 4:57pm
We used a similar script and found we had to run a harware inventory after the site assignment for it to work. We added this to our script to do so:
Sub RunHardwareInventory()
' Set the required variables.
Dim actionNameToRun
actionNameToRun = "Hardware Inventory Collection Cycle"
' Create the CPAppletMgr instance.
Dim controlPanelAppletManager
Set controlPanelAppletManager = CreateObject("CPApplet.CPAppletMgr")
' Get the available ClientActions object.
Dim clientActions
Set clientActions = controlPanelAppletManager.GetClientActions()
' Loop through the available client actions. Run the matching client action when it is found.
Dim clientAction
For Each clientAction In clientActions
If clientAction.Name = actionNameToRun Then
clientAction.PerformAction
End If
Next
' wscript.echo "Ran: " & actionNameToRun
End Sub
Free Windows Admin Tool Kit Click here and download it now
October 15th, 2010 5:28pm
do u want me to run the above script exclusively on every client after running the site-code re-assignment script. or do you want me to include this in the same script.
can u pls give me the full script that you used for sitecode reassignment.
thanks
Sameer
October 15th, 2010 5:34pm
Sure, here it is:
Option Explicit
On Error Resume Next
Dim oArg, I, SiteCode
Set oArg = WScript.Arguments
If WScript.Arguments.Length > 1 OR WScript.Arguments.Length < 1 Then
wscript.echo "Syntax: <script.vbs SiteCode> "
WScript.Quit(-1)
End If
For I=0 To oArg.count -1
SiteCode = oArg(I)
Call SetAssignedSite(SiteCode)
Call RunHardwareInventory()
Next
WScript.Quit(0)
Sub SetAssignedSite (newSite)
Dim oSMSClient
Set oSMSClient = CreateObject ("Microsoft.SMS.Client")
If Err.Number <>0 Then
'wscript.echo "Can not create SMS Client Object - Terminating."
Exit Sub
End If
' WScript.Echo "Current SiteCode: " & oSMSClient.GetAssignedSite
If oSMSClient.GetAssignedSite = newSite then
'wscript.echo "No need to change site code."
Exit Sub
End If
oSMSClient.SetAssignedSite newSite,0
'Wscript.Echo "Assigned SiteCode is: " & oSMSClient.GetAssignedSite
Set oSMSClient=Nothing
End Sub
Sub RunHardwareInventory()
' Set the required variables.
Dim actionNameToRun
actionNameToRun = "Hardware Inventory Collection Cycle"
' Create the CPAppletMgr instance.
Dim controlPanelAppletManager
Set controlPanelAppletManager = CreateObject("CPApplet.CPAppletMgr")
' Get the available ClientActions object.
Dim clientActions
Set clientActions = controlPanelAppletManager.GetClientActions()
' Loop through the available client actions. Run the matching client action when it is found.
Dim clientAction
For Each clientAction In clientActions
If clientAction.Name = actionNameToRun Then
clientAction.PerformAction
End If
Next
' wscript.echo "Ran: " & actionNameToRun
End Sub
Free Windows Admin Tool Kit Click here and download it now
October 15th, 2010 5:46pm
The site code reassignment script is not your problem. Your script should work fine for reassigning the clients.
John Marcum | http://myitforum.com/cs2/blogs/jmarcum |
October 15th, 2010 5:47pm
i have pushed the script to one of the clients...will let u know the findings....pls bear with me
Free Windows Admin Tool Kit Click here and download it now
October 15th, 2010 6:10pm
Hi Sameer,
I am looking to do the same thing, did this work for you?
November 5th, 2010 5:50pm
Hi Sameer,
I am looking to do the same thing, did this work for you?
Are you just wanting to reassign some clients? I've used that script, it works.
John Marcum | http://myitforum.com/cs2/blogs/jmarcum |
Free Windows Admin Tool Kit Click here and download it now
November 5th, 2010 6:54pm