Created
October 17, 2019 17:45
-
-
Save joerodgers/16a9250e2fa9de72abe58bcece709519 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-DomainPrincipal | |
{ | |
[CmdletBinding()] | |
param | |
( | |
[Parameter(Mandatory=$true,ParameterSetName='DistinguishedName')] | |
[Parameter(Mandatory=$true,ParameterSetName='Name')] | |
[Parameter(Mandatory=$true,ParameterSetName='SamAccountName')] | |
[Parameter(Mandatory=$true,ParameterSetName='Sid')] | |
[Parameter(Mandatory=$true,ParameterSetName='UserPrincipalName')] | |
[Parameter(Mandatory=$true,ParameterSetName='Guid')] | |
[ValidateSet("User", "Group")] | |
[string]$PrincipalType, | |
[Parameter(Mandatory=$true,ParameterSetName='DistinguishedName')] | |
[string]$DistinguishedName, | |
[Parameter(Mandatory=$true,ParameterSetName='Name')] | |
[string]$Name, | |
[Parameter(Mandatory=$true,ParameterSetName='SamAccountName')] | |
[string]$SamAccountName, | |
[Parameter(Mandatory=$true,ParameterSetName='Sid')] | |
[string]$Sid, | |
[Parameter(Mandatory=$true,ParameterSetName='UserPrincipalName')] | |
[string]$UserPrincipalName, | |
[Parameter(Mandatory=$true,ParameterSetName='Guid')] | |
[string]$Guid | |
) | |
begin | |
{ | |
Add-Type -AssemblyName System.DirectoryServices.AccountManagement | |
$principalContext = New-Object System.DirectoryServices.AccountManagement.PrincipalContext( [System.DirectoryServices.AccountManagement.ContextType]::Domain ) | |
} | |
process | |
{ | |
if( $PrincipalType -eq "User" ) | |
{ | |
[System.DirectoryServices.AccountManagement.UserPrincipal]::FindByIdentity( $principalContext, [System.DirectoryServices.AccountManagement.IdentityType]::$($PSCmdlet.ParameterSetName),(Get-Variable -Name $PSCmdlet.ParameterSetName -ValueOnly) ) | |
} | |
else | |
{ | |
[System.DirectoryServices.AccountManagement.GroupPrincipal]::FindByIdentity( $principalContext, [System.DirectoryServices.AccountManagement.IdentityType]::$($PSCmdlet.ParameterSetName),(Get-Variable -Name $PSCmdlet.ParameterSetName -ValueOnly) ) | |
} | |
} | |
end | |
{ | |
} | |
} | |
Add-PSSnapin Microsoft.SharePoint.PowerShell | |
$webApplications = @(Get-SPWebApplication) | |
foreach( $webApplication in $webApplications ) | |
{ | |
$superReader = ($webApplication.Properties["portalsuperreaderaccount"] -split "\\")[-1] | |
$superUser = ($webApplication.Properties["portalsuperuseraccount"] -split "\\")[-1] | |
Get-DomainPrincipal -PrincipalType User -SamAccountName $superUser | SELECT @{N="WebApp";e={$webApplication.Url}}, @{N="Role";e={"SuperReader"}}, SamAccountName, LastPasswordSet, Enabled | |
Get-DomainPrincipal -PrincipalType User -SamAccountName $superReader | SELECT @{N="WebApp";e={$webApplication.Url}}, @{N="Role";e={"SuperUser"}}, SamAccountName, LastPasswordSet, Enabled | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment