Wednesday, April 19, 2017

SharePoint 2013 TIP: How to get managed account passwords via PowerShell

To get the password for each and every  managed account in the farm, just run this PowerShell script by Shannon Bray in an elevated SharePoint Management Shell:
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}}

You can also obtain the password of any web application pool by running this in an elevated command shell:
C:\Windows\System32\inetsrv\appcmd list apppool "[App Pool Name]" /text:*

References

No comments: