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 Script to Find Specific user Permission for a SharePoint Site
WhatsApp
Karthik Muthu Karuppan
Jan 27
2015
29.5
k
0
0
FindSpecificUserPerm
$LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
$LogFile =
".\UserPermissionsDetailsPatch-$LogTime.rtf"
# Add SharePoint PowerShell Snapin
if
( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $
null
) {
Add-PSSnapin Microsoft.SharePoint.Powershell
}
$scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
Set-Location $scriptBase
#Deleting any .rtf files in the scriptbase location
$FindRTFFile = Get-ChildItem $scriptBase\*.* -include *.rtf
if
($FindRTFFile)
{
foreach($file
in
$FindRTFFile)
{
remove-item $file
}
}
start-transcript $logfile
$siteCollection = read-host
"Enter the site collection URL "
$username = read-host
"Enter the user name (e.g: domain\username) "
$site = get-spsite $siteCollection
foreach($web
in
$site.allwebs)
{
#Check if the user is site collection administrator
$getuser = get-spuser -identity $username -web $web.url
if
($getuser.issiteadmin)
{
write-host
"The user "
$username
" is a site collection administrator"
-
for
green
}
$permissionInfo = $web.GetUserEffectivePermissionInfo($Username)
$roles = $permissionInfo.RoleAssignments
write-host
"Now checking the permissions of the user "
$Username
" in the site "
$web.Url -fore yellow
for
($i = 0; $i -lt $roles.Count; $i++)
{
$bRoles = $roles[$i].RoleDefinitionBindings
foreach ($roleDefinition
in
$bRoles)
{
if
($roles[$i].Member.ToString().Contains(
'\'
))
{
write-host
"The User "
$username
" has direct permissions "
$roleDefinition.Name -fore green
}
else
{
write-host
"The User "
$username
" has permissions "
$roleDefinition.Name
" given via "
$roles[$i].Member.ToString() -fore green
}
}
}
}
PowerShell
SharePoint
Up Next
Powershell Script to Find Specific user Permission for a SharePoint Site