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()
Leave a Reply