Click here to Skip to main content
13,147,956 members (81,020 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


2 bookmarked
Posted 21 Jul 2014

Powershell To update Services Password, Sharepoint Managed Acount Password and IIS AppPool Password

, 21 Jul 2014
Rate this:
Please Sign up or sign in to vote.
Update Password using PowerShell

Powershell To update Services Password, Sharepoint Managed Acount Password and IIS AppPool Password

Many a times there is a need to update the changed password in Virtual Machines. It can be done manually. But doing it via Powershell will save us a lot of time.


After browsing for a while, I couldn't find an article that pointed me in doing all the above using one script. So I thought to share the powershell comands that I just put together, which can be optimized/refactored by admins to use them in prod environment.

Using the code

// Save the below powershell code as ps1 and run in Powershell
// Update Domain, UserName and Password with your actual values

$localaccount = "domain\username"
$newpassword = "************"

#Set Execution Policy
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -force

#Import SharePoint Module
Add-PSSnapin Microsoft.SharePoint.PowerShell -EA silentlycontinue

#Update Service Account
Write-Host "Updating Password for Services" -foregroundcolor green
$services = Get-WmiObject win32_Service | where { $_.startname -eq $localaccount}

foreach ($service in $services)
    #Update Password
    Write-Host "Updating Password." -foregroundcolor 13
    $status = $service.Change($null,$null,$null,$null,$null,$null, $localaccount, $newpassword)
    Write-Host "Status:  " $status.ReturnValue -foregroundcolor 13	

#Stop Service
Write-Host "Stop all running Services." -foregroundcolor green
Get-WmiObject win32_Service | where { ($_.startname -eq $localaccount -And $_.state -ne "Stopped" -And  $_.startmode -ne "Disabled") } | stop-service -force

#Start Service
Write-Host "Restarting stopped Services" -foregroundcolor green
Get-WmiObject win32_Service | where { ($_.startname -eq $localaccount -And $_.state -ne "Running" -And  $_.startmode -ne "Disabled") } | start-service

#Update Sharepoint Managed Account
$ManagedAccount = Get-SPManagedAccount -Identity $localaccount
$securePassword = ConvertTo-SecureString -String $newpassword -AsPlainText -Force

Write-Host "Please wait while Passwod for SharePoint Managed Account gets updated." -foregroundcolor red

Set-SPManagedAccount -Identity $ManagedAccount -ExistingPassword $securePassword -Confirm:$false

Write-Host "Password for SahrePoint Updated Successfully" -foregroundcolor green

#Update App Pool Accounts
Import-Module WebAdministration

#Restart IIS
Write-Host "Restarting IIS. " -foregroundcolor green
iisreset /noforce

$appPools = Get-ChildItem IIS:\appPools  | where {$_.state -ne "Started"}

foreach ($appPool in $appPools) 
    if ($appPool.processModel.userName -eq $localaccount)
        $appPoolName = $appPool.Name
        $appPool.processModel.password =  $newpassword	
        $appPool | Set-Item
        Write-Host "Password for AppPool " $appPoolName " updated successfully"  -foregroundcolor green

#Restart IIS
Write-Host "Restarting IIS after password reset. " -foregroundcolor green
iisreset /noforce

Write-Host "IIS Restarted Successfully. " -foregroundcolor green


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Rocky R. Fernandes
Software Developer (Senior) 3MD Tech
United States United States
Rocky Fernandes has over 11 years of experience in Software Industry mostly developing Web Applications. Other than having vast experience in various Microsoft Technologies like SharePoint, ASP.Net, C#, VB.Net, Silverlight, WCF, MVC, Web API, SQL Server, ADO.Net, ADOMD.Net, LINQ, Entity Framework, Exchange Web Service(EWS) API, he also has vast experience in Client Side Scripting like JavaScript, jQuery, JSON, JSONP, CSS and HTML5. He is very much passionate in programming and enjoys doing it. In the academic side he holds a BE Degree in Computer Science & Engineering. In the certification side he holds certifications in Sharepoint 2010, SharePoint 2013, ASP.Net & SQL Server.

In most of the free time, he will be spending in technical activities like researching solutions, reading technical articles and learning new stuff. He believes that following Best Practices and Coding standard is a way to go for producing an efficient, quality & satisfactory application.


You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170915.1 | Last Updated 21 Jul 2014
Article Copyright 2014 by Rocky R. Fernandes
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid