Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Update SharePoint Managed Account Password on all Farm Layers: IIS, Windows Services and SharePoint Services
#Author: Antonio Leonardo de Abreu Freire, Microsoft Certified ID: 13271836
Set-Executionpolicy -Scope CurrentUser -ExecutionPolicy UnRestricted
Import-Module WebAdministration
$serviceAccount = Read-Host -Prompt "Please enter the user (in DOMAIN\username format)."
$securePass = Read-Host "Now, what is this user's password? Please enter (this field will be encrypted)." -AsSecureString
$plainTextPass = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($securePass))
$applicationPools = Get-ChildItem IIS:\AppPools | where { $_.processModel.userName -eq $serviceAccount }
foreach($pool in $applicationPools)
{
$pool.processModel.userName = $serviceAccount
$pool.processModel.password = $plainTextPass
$pool.processModel.identityType = 3
$pool | Set-Item
}
$serverName = $env:computername
$shpServices = gwmi win32_service -computer $serverName | where {$_.StartName -eq $serviceAccount}
foreach($service in $shpServices)
{
$service.change($null,$null,$null,$null,$null,$null,$null,$plainTextPass)
}
Add-PSSnapin Microsoft.SharePoint.PowerShell
$managedAccount = Get-SPManagedAccount | where { $_.UserName -eq $serviceAccount }
Set-SPManagedAccount -Identity $managedAccount -ExistingPassword $securePass –UseExistingPassword $true
if((Get-SPFarm).DefaultServiceAccount.Name -eq $serviceAccount)
{
stsadm.exe –o updatefarmcredentials –userlogin $serviceAccount –password $plainTextPass
}
iisreset /noforce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.