2

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()
    }
}

1 Answer 1

2

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.

1
  • +1 managed accounts
    – shufler
    Commented Nov 15, 2011 at 0:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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