Thursday, May 1, 2014

SharePoint 2010 - Creating and using a managed account through PowerShell

I had a client that called saying they could no longer access their SharePoint site nor the Central Administration site.  The cause was related to invalid passwords to the managed accounts.  The client had changed the account passwords on the services and application pools manually outside of SharePoint.  To make matters worse, they could not tell me the passwords of the account since they are handled by an outside network vendor.   Even worse the vendor tries to remain hands off with SharePoint, so I could not send them a script for them to run to resolve the problem.  My account is a SharePoint Farm Administrator.  Therefore, my plan was to use my account to get Central Administration operating again.  Then, they could go in and change the passwords through the Central Administration interface.   

I remoted into the SharePoint server and opened the SharePoint 2010 Management Shell as Administrator.  I executed the Get-SPManagedAccount cmdlet to get a listing of the current managed accounts.  I did not see my account listed, which was to be expected.  I created a new managed account using my credentials.  Here is the powershell commands that I executed.

$svcAccount = “username”
$password = "SamplePassword"
$securePassword = ConvertTo-SecureString -String $password -AsPlainText –Force
$userName = $env:USERDOMAIN + "\" + $svcAccount
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $userName, $securePassword
New-SPManagedAccount -Credential $cred

My next step was to switch Central Administration to use this new managed account.  Here are the SharePoint commands that I used to do that:

$WebApplication = Get-SPWebApplication <ApplicationURL>;
$ManagedAccount = Get-SPManagedAccount -Identity "<Domain Name>\<UserName>";
$WebApplication.ApplicationPool.ManagedAccount = $ManagedAccount;
$WebApplication.ApplicationPool.Update();
$WebApplication.update();

Once I did that, I restarted the Central Administration application pool in IIS.  I was then able to open Central Administration.  I contacted the client to let them know they could go into Central Administration and change the managed account passwords.  Once that was done, I switched Central Administration back to the original managed account and removed mine from the managed account list.  All of the SharePoint sites and services were operating as normal.

No comments:

Post a Comment