Powershell script returns usernames and passwords of all SharePoint service

Powershell script returns usernames and passwords of all SharePoint service

# Bind to the local SharePoint farm
$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local

# Bind to the collection of all farm services
$spcredentials = $farm.Services | 
    # Sort farm services by type
    sort -Property TypeName | 
        # Only select those logical services that are backed up by a physical NT service,
        # excluding services not running under either a domain or LSA account `
        Where-Object {($_ -is [Microsoft.SharePoint.Administration.SPWindowsService]) `
            -and (($spi = $_.ProcessIdentity).Username -notlike "NT AUTHORITY\*")} | 
               # Store information about service account in a custom object through the Create-Object function
               # and store the object in the $spcredentials array
               ForEach-Object {Create-Object "Service" $_.TypeName $spi.Username $spi.Password}

# Bind to the collection of SPWebService instances in the farm and process them one by one
foreach ($ws in (New-Object -TypeName Microsoft.SharePoint.Administration.SPWebServiceCollection -ArgumentList $farm))
{
    # Bind to the collection of all IIS application pools associated with the current instance of SPWebService
    $spcredentials += $ws.ApplicationPools | 
        # Exclude pools not running under wither a domain or LSA account
        Where-Object {$_.Username -notlike "NT AUTHORITY\*"} | 
            # Store information about service account in a custom object through the Create-Object function
            # and store the object in the $spcredentials array 
            ForEach-Object {Create-Object "ApplicationPool" $_.Name $_.Username $_.Password}
}

# Return account information to the standard output
$spcredentials | Format-List
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s