Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
PowerShell : List All the users for a Site Collection
WhatsApp
Ketak Bhalsing
May 20
2016
7.4
k
0
1
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
Up Next
PowerShell : List All the users for a Site Collection