I am in a position where service credentials change quite a lot, I would normally use central admin to change the credentials but quite often the application pool that runs that is using the same credentials which I want to change.
I've tried writing the following powershell script but I always get FALSE
as the result of SetPassword. Any ideas what i am doing wrong?
$login
and $password
are parameters which are passed in to the script.
$managedAccount = Get-SPManagedAccount
$secureString = convertto-securestring $password -asplaintext -force
##Set-SPManagedAccount -Identity $managedaccount -ConfirmPassword $securestring -NewPassword $secureString
$Apps = Get-SPWebApplication
foreach ($App in $Apps)
{
$AppPool = $App.ApplicationPool
#$AppPool
#Write-Host "$($AppPool.Username) $($login) $($AppPool.Username -eq $login)"
if ($App.ApplicationPool.Username -eq $login)
{
write-host "setting credentials"
$App.ApplicationPool.CurrentIdentityType= [Microsoft.SharePoint.Administration.IdentityType]::SpecificUser
$App.ApplicationPool.Username = $login
$result = $App.ApplicationPool.SetPassword($securestring)
$result
# Save the settings
$App.ApplicationPool.UpdateCredentials($login)
# Roll the settings out via a Admin Job
$App.ApplicationPool.Provision()
}
}