SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
    #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) 

        # Save the settings

        # Roll the settings out via a Admin Job
share|improve this question
up vote 2 down vote accepted

First i would set a seperate $applicationPool variable and use that. $applicationPool = $app.ApplicationPool Also you should probably call Update on application pool.

But why dont you use managed accounts for this? That way you get all the password sync etc that is new in SP2010

$applicationPool.CurrentIdentityType = [Microsoft.SharePoint.Administration.IdentityType]::SpecificUser $applicationPool.ManagedAccount = $Account $applicationPool.Update()

You can then manage the password on your managed account using the ChangePassword() method on SPManagedUser.

share|improve this answer
Thanks Anders, I'll give that a go today and Accept the answer if it works. – Mauro Aug 4 '10 at 12:13
+1 managed accounts – shufler Nov 15 '11 at 0:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.