Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antonio-leonardo/a86d2fc714e3a4a6b20f8559e1ba7ad0 to your computer and use it in GitHub Desktop.
Save antonio-leonardo/a86d2fc714e3a4a6b20f8559e1ba7ad0 to your computer and use it in GitHub Desktop.
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, vide https://www.youracclaim.com/users/antonioleonardo/badges ####
#########################################################################################################
## Update SharePoint Account Password on all Farm Layers: IIS, Windows Services and SharePoint Services #
#########################################################################################################
#########################################################################################################
########### Don't Forget this Script Premisses! The current user to execute this script needs: ##########
########### a)Belongs to Farm Administrator Group; ######################################################
########### b)local machine Administrator (on any SharePoint Farm server); ##############################
########### c)SQL Server SecurityAdmin profile (on SharePoint database instance); #######################
########### d)db_owner on databases "SharePoint_Config" and "SharePoint_Admin_<any guid>"; ##############
#########################################################################################################
#########################################################################################################
#########################################################################################################
Set-Executionpolicy -Scope CurrentUser -ExecutionPolicy UnRestricted -Force
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 -Confirm:$False
if((Get-SPFarm).DefaultServiceAccount.Name -eq $serviceAccount)
{
stsadm.exe –o updatefarmcredentials –userlogin $serviceAccount –password $plainTextPass
}
iisreset /noforce
@fabio6864
Copy link

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
Copy link
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
Copy link
Author

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