SharePoint Managed accounts feature was introduced in its 2010 version, and of course its a wonderful feature to manage service accounts (I remember those old days.. We used to create a batch file to update password for each and everything in SharePoint 2007!).

get managed account password in sharepoint using powershell

So, We utilized managed accounts in SharePoint 2013, enabled automatic password change. All went well until we needed the password for a particular managed account to install a third-party add-on! Luckily found this script to get managed account passwords in SharePoint.

Important: You must run this script as Farm Administrator! and make sure you are running the script as “Administrator”!!

Recover SharePoint managed account password

Here is the PowerShell script to retrieve SharePoint managed account passwords:

Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

function Bindings()
 return [System.Reflection.BindingFlags]::CreateInstance -bor
 [System.Reflection.BindingFlags]::GetField -bor
 [System.Reflection.BindingFlags]::Instance -bor
function GetFieldValue([object]$o, [string]$fieldName)
 $bindings = Bindings
 return $o.GetType().GetField($fieldName, $bindings).GetValue($o);
function ConvertTo-UnsecureString([System.Security.SecureString]$string)
 $intptr = [System.IntPtr]::Zero
 $unmanagedString = [System.Runtime.InteropServices.Marshal]::SecureStringToGlobalAllocUnicode($string)
 $unsecureString = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($unmanagedString)
 return $unsecureString

Get-SPManagedAccount | select UserName, @{Name="Password"; Expression={ConvertTo-UnsecureString (GetFieldValue $_ "m_Password").SecureStringValue}}

This script decrypts and retrieves all SharePoint 2010 / SharePoint 2013 managed account passwords along with its user names.

Related post: How to Get IIS Application Pool Password?

Source link