Creating or Re-Creating Managed Accounts (w/ Powershell)

When creating a farm using powershell, you need to create the managed accounts that your service applications will use.  Here’s a script written by Stephen Swinney, Rackspace Senior SharePoint Engineer that does just that!

$Credentials = @()
				
				#Create User Variables
				$FarmUser = "Domain\SP_Farm"
				$ServcAppUser = "Domain\SP_SA_AP"
				$SiteAppUser = "Domain\SP_Site_AP"
				$SearchSvcUser = "Domain\SP_SearchSvc"
				
				#Create Password Variables
				$FarmPass = ConvertTo-SecureString -String "$*t6uxNM3AL4_*R4" -AsPlainText -Force
				$ServcAppPass = ConvertTo-SecureString -String "Htfa3S9^wZ6?CgmX" -AsPlainText -Force
				$SiteAppPass = ConvertTo-SecureString -String "Rt)4(97#kDum" -AsPlainText -Force
				$SearchSvcPass = ConvertTo-SecureString -String "2t+Z(tm2)NU6" -AsPlainText -Force
				
				#Create object & add to array
				$Credentials += New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $FarmUser, $FarmPass
				$Credentials += New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $ServcAppUser, $ServcAppPass
				$Credentials += New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $SiteAppUser, $SiteAppPass
				$Credentials += New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $SearchSvcUser, $SearchSvcPass 
				
				#Loop through array and create managed accounts
					foreach ($Credential in $Credentials)
						{
						Write-Host "Creating new managed account:" $Credential.UserName -foregroundcolor cyan
						New-SPManagedAccount -Credential $Credential
						}
				#End Script
				Write-Host "All Managed Accounts Created" -foregroundcolor cyan

 

Note: you could also use this script to re-create the managed accounts in a situation where they had been deleted.

 

This approach is much easier and cleaner than entering, New-SPManagedAccount, then manually having to type in the cryptic password and user account with domain\ prefix.