Changing a Site Name in Configuration Manager via PowerShell.

PowerShell and WMI:

As in my recent posts, we can find our help in PowerShell and WMI. There only thing we need to know is where can we find an editable property for the current site name. That property can be found in the SMS_SCI_SiteDefinition class in WMI. Now the script is “easy” to create and complete, as it only needs three things:

  1. Create an object of the SiteDefinition that we want to change.
  2. Change the property SiteName to our new name.
  3. Save the changes.

This gives us the following small script (really, this is all!).

###################################################################################################

# Project: Change Site Name

# Date: 20-05-2013

# By: Peter van der Woude

# Version: 1.0 Public

###################################################################################################

[CmdletBinding()]

param (

[string]$SiteCode,

[string]$SiteServer,

[string]$SiteName

)

function Change-SiteName {

    $Site = Get-WmiObject -Class SMS_SCI_SiteDefinition -Namespace root/SMS/site_$($SiteCode) -ComputerName $SiteServer | Where-Object -FilterScript {$_.SiteCode -eq $SiteCode}

    $Site.SiteName = $SiteName

    $Site.Put()

}

Change-SiteName

Either copy the code, or download it via the TechNet Galleries. This script needs a few parameters, of which the SiteCode is the most important. That parameter will be used for a WMI connection and for determining the of which site the name has to be changed.

Example: PowerShell.exe -ExecutionPolicy ByPass .\ChangeSiteName_v1_0.ps1 -SiteCode <SiteCode> -SiteServer <SiteServer> -SiteName <SiteName>

 

Thanks to Peter van der Woude.