if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
param
(
[parameter(Mandatory=$false)][string]$RootSiteUrl = "<Your Site Collection URL goes here>"
)
# Array to hold the user collection
$userCollection = @()
$users = Get-SPUser -Web $RootSiteUrl -Limit ALL
foreach ($domainUser in $users)
{
# Get Domain from user login name
$domainUserSTR = $domainUser.Userlogin
$domain = $domainUserSTR.Split("\")[0]
$ispipe = $domain.IndexOf("|")
if ($ispipe -ne -1)
{
$domain = $domain.split("|")[1]
}
$user = New-Object System.Object
$user | Add-Member -MemberType NoteProperty -Name "Domain" -Value $domain
$user | Add-Member -MemberType NoteProperty -Name "UserLogin" -Value $domainUser.UserLogin
$user | Add-Member -MemberType NoteProperty -Name "DisplayName" -Value $domainUser.DisplayName
$userCollection += $user
Write-Host $user.UserLogin
}
$userCollection | Export-CSV -Path "C:\UserLists.csv" -NoTypeInformation
Write-Host "Finished."This PowerShell script to list all the users listed under site collection.
