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 Script to Find Specific user Permission for a SharePoint Site
Karthik Muthu Karuppan
Jan 27
2015
Code
29.3
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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