Wednesday, January 1, 2014

How to Get Managed Account Password in SharePoint?

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!). 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"!!

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
 [System.Reflection.BindingFlags]::NonPublic
}
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)
 [System.Runtime.InteropServices.Marshal]::ZeroFreeGlobalAllocUnicode($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?



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...