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. The full article with the prerequisites to execute this script at this URL: https://github.com/antonio-leonardo/UpdateSharePointManagedAccountPassword or https://www.codeproject.com/Articles/5092791/Update-SharePoint-Managed-Account-Pass…
#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
@fabio6864

This comment has been minimized.

Copy link

fabio6864 commented Nov 28, 2019

PS C:\temp> .\Shp.EmergencySPManagedAccountUpdate.ps1
At C:\temp\Shp.EmergencySPManagedAccountUpdate.ps1:28 char:1

  • }
  • ~
    Unexpected token '}' in expression or statement.
    • CategoryInfo : ParserError: (:) [], ParseException
    • FullyQualifiedErrorId : UnexpectedToken
@antonio-leonardo

This comment has been minimized.

Copy link
Owner Author

antonio-leonardo commented Nov 29, 2019

Hi Fabio,

I'm so sorry for this, I do not make reference to fulll article that means this script, at this URL: https://github.com/antonio-leonardo/UpdateSharePointManagedAccountPassword or https://www.codeproject.com/Articles/5092791/Update-SharePoint-Managed-Account-Password-on-All
This article contains all pre-reqs to execute this script.

Thanks for your feed-back.

@antonio-leonardo

This comment has been minimized.

Copy link
Owner Author

antonio-leonardo commented Nov 29, 2019

You may also read the discussion about this script in published LinkedIn, at this URL: https://www.linkedin.com/feed/update/urn:li:activity:6555412213232910336

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.