Wednesday, June 20, 2012

powershell change service account password sharepoint

Usually, We set all the sharepoint admin accounts or service account passwords with expiry period.

After that particular period passwords will be expired. At this point of time we need to update the passwords from either Central admin or Powershell.

Here is the powershell code to update password of a sharepoint account .


$version = $host | select version
if ($ver.Version.Major -gt 1)  {$Host.Runspace.ThreadOptions = "ReuseThread"}

# 1. Adding sharepoint snap-in
Add-PsSnapin Microsoft.SharePoint.PowerShell
Set-location $home

# 2. Provide the service account name
$ServiceAccountName = Read-Host 'Service Account'

$managedAccount = Get-SPManagedAccount $ServiceAccountName

# 3. Get and confirm the serice account new password
$password = Read-Host 'Enter Password' -AsSecureString
$passwordConfirmation = Read-Host 'Confirm Password' -AsSecureString

# 4. Command to change the password
Set-SPManagedAccount -Identity $managedAccount -NewPassword $password -ConfirmPassword $passwordConfirmation -SetNewPassword


Happy sharepoint coding

No comments:

Post a Comment