SCCM – Change Site Code on multiple computers

If you had to change the sccm client site code on multiple computers (after sccm migration or new/upgraded server installation) nowadays you might have discovered that it’s not as easy as it should be. You could push the new site client to all computers generating a lot of heat to the network or try deprecated wmic (miserably fails). I wanted to avoid mass client push and found that the following quick and dirty script works well:

First create a list of all computers using your favorite method, I already have a text file with them so I’ll just use it, it’s named mycomps.txt and it is in my current folder.

#Create variable with all computers from text file
$wst = Get-Content .\mycomps.txt

#Loop through them with foreach and change site code with invoke-command
foreach ($comp in $srv) {
Invoke-Command -ComputerName $comp -ScriptBlock {($smsclinet = New-Object -comobject "Microsoft.SMS.Client") , ($smsclient.SetAssignedSiteCode('XYZ'))
}}
#If you want to check the result change 

($smsclient.SetAssignedSiteCode('XYZ') 

#to 

($smsclient.GetAssignedSiteCode()

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.