Skip to content

Instantly share code, notes, and snippets.

@joerodgers
Created October 17, 2019 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joerodgers/16a9250e2fa9de72abe58bcece709519 to your computer and use it in GitHub Desktop.
Save joerodgers/16a9250e2fa9de72abe58bcece709519 to your computer and use it in GitHub Desktop.
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