SCCM – Change Site Code on multiple computers

Our Score
Click to rate this post!
[Total: 0 Average: 0]

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 $wst) {
Invoke-Command -ComputerName $comp -ScriptBlock {($smsclinet = New-Object -comobject "Microsoft.SMS.Client") , ($smsclient.SetAssignedSite('XYZ'))
}}
#If you want to check the result change 

($smsclient.SetAssignedSite('XYZ') 

#to 

($smsclient.GetAssignedSiteCode()

Our Score
Click to rate this post!
[Total: 0 Average: 0]

Comments

3 responses to “SCCM – Change Site Code on multiple computers”

  1. We have to change the SetAssignedSiteCode –> SetAssignedSite to work.

  2. Hi Ivan,

    Can you explain the $srv? I don’t see the variable used in the script.

    1. Thank you for your comment – my mistake $srv should actually be $wst – fixed

      Same for the SetAssignedSite – fixed as well.

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.