I was at a clients the other day and wanted to update the proxy account information for the Primary Site Server so thought I would script it quickly. This Script will create an account in ConfigMgr and then associate that with the Proxy details specified to the Site System. It must be run with access to the ConfigMgr Module for PowerShell and administrative rights.
Here it is:
######################################################################################################################### #Author: SCCMOG - Richie Schuster - SCCMOG.COM # #Date: 02/05/2017 # #Name: Set-CMProxyAccount.ps1 # #RunAs CMD: Powershell.exe -Executionpolicy Bypass -File Set-CMProxyAccount.ps1 -Account SCCMOG\Admin # # -Password CantCrackMe -SSFQDN CM-01.SCCMOG.COM -SiteCode SOG -ProxSName proxy.sccmog.com -ProxySPort 8080# # Just running the script will prompt for all parameters. # #Description: This script will add a new account to the site and then associate it with the proxy account for the site # # system. # ######################################################################################################################### Param ( [parameter(mandatory=$true,HelpMessage="Please, provide a account name. Domain\Account or Account")][ValidateNotNullOrEmpty()]$Account, [parameter(mandatory=$true,HelpMessage="Please, provide the password to be used.")][ValidateNotNullOrEmpty()]$Password, [parameter(mandatory=$true,HelpMessage="Please, provide the Site Server FQDN.")][ValidateNotNullOrEmpty()]$SSFQDN, [parameter(mandatory=$true,HelpMessage="Please, provide the Code.")][ValidateNotNullOrEmpty()]$SiteCode, [parameter(mandatory=$true,HelpMessage="Please, provide Proxy Server Name.")][ValidateNotNullOrEmpty()]$ProxySName, [parameter(mandatory=$true,HelpMessage="Please, provide Proxy Server Port.")][ValidateNotNullOrEmpty()]$ProxySPort ) # Check for elevation Write-Host "Checking for elevation" If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(` [Security.Principal.WindowsBuiltInRole] "Administrator")) { Write-Warning "Oupps, you need to run this script from an elevated PowerShell prompt!`nPlease start the PowerShell prompt as an Administrator and re-run the script." Write-Warning "Aborting script..." Break } # Import the ConfigurationManager.psd1 module Write-Host "Importing ConfigMgr Module..." -ForegroundColor Yellow Import-Module "$($ENV:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1" # Set the current location to be the site code. Write-Host "Setting Location to ConfigMgr Drive..." -ForegroundColor Yellow Set-Location "$SiteCode`:" #Store the pass as a secure string Write-Host "Storing Password securely...." -ForegroundColor Yellow $Secure = ConvertTo-SecureString -String $Password -AsPlainText -Force #Create Account Write-Host "Creating New Account $Account...." -ForegroundColor Yellow New-CMAccount -UserName $Account -Password $Secure -SiteCode $SiteCode #Set Site Server Proxy Write-Host "Setting Proxy information...." -ForegroundColor Yellow Set-CMSiteSystemServer -SiteSystemServerName $SSFQDN -SiteCode $SiteCode -EnableProxy $True -ProxyServerName $ProxySName` -ProxyServerPort $ProxySPort -ProxyAccessAccount (Get-CMAccount $Account) -PassThru ########################################################################################################################
Demonstration of running the script:
Site System Properties after running Script:
Account Properties: