SCCM – Create New Site System Automatically

email me

Download: http://eddiejackson.net/apps/ConfigMgr2012PowerShellCmdlets.msi

Also see: SCCM – Automated WSUS & SUP Install

Save as: Create-NewSiteSystem.ps1

param (
[string]$SiteCode,
[string]$NewSUPServerName,
[string]$MPServer
)

Function Create-NewSystem {
$Hive = "LocalMachine"
$ServerName = "$($MPServer)"
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]$Hive,$ServerName,[Microsoft.Win32.RegistryView]::Registry64)
$Subkeys = $reg.OpenSubKey('SOFTWARE\Microsoft\SMS\Setup\')
$AdminConsoleDirectory = $Subkeys.GetValue('UI Installation Directory')
switch (Test-Path $AdminConsoleDirectory)
{
$true { Import-Module "$($AdminConsoleDirectory)\bin\ConfigurationManager.psd1" }
$false {
Write-Verbose "$($AdminConsoleDirectory) does not exist. Trying alternate path under ProgramFilesx86"
$AdminConsoleDirectory = "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole"
Import-Module "$($AdminConsoleDirectory)\bin\ConfigurationManager.psd1"
}
}

Set-Location "$($SiteCode):"

if (-not (Get-CMSiteSystemServer -SiteSystemServerName $NewSUPServerName -SiteCode $SiteCode))
{
New-CMSiteSystemServer -ServerName $NewSUPServerName -SiteCode $SiteCode

if (-not (Get-CMSiteSystemServer -SiteSystemServerName $NewSUPServerName -SiteCode $SiteCode))
{
Write-Error "The Site System $($NewSUPServerName) has not been created. Please check the logs for further information"
exit 1
}
}
}

Create-NewSystem