Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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()
    }
}
share|improve this question

1 Answer 1

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

 
discard

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.