TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
PowerShell : List All the users for a Site Collection
Ketak Bhalsing
May 20
2016
Code
7.3
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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."
PowerShell
SharePoint
Users