9

By clicking "Site Settings" > "Site Permission" I can get a list of permission setup for the site. I need to export the exact list with PowerShell to CSV. May I know how to do it?

By using

$web = Get-SPWeb "http://url"
$web.Permissions

I get a list very similar. However it is showing "BasePermissions" (e.g. ViewListItems, AddListItems, EditListItems, DeleteListItems, OpenItems, ViewVersions, DeleteVersions, ManagePersonalViews, ViewFormPages, Open, ViewPages, CreateSSCSite, ManagePermiss ions, BrowseDirectories, BrowseUserInfo, UseClientIntegration).

It is not what I want. I want to show the permission level exactly same as GUI provide. (e.g. Full Control, Limited Access)

Could you please advice?

3 Answers 3

7

Try this one,

foreach($roleAssignment in $web.RoleAssignments) 
 { 
  if(-not [string]::IsNullOrEmpty($roleAssignment.Member.Xml)) 
   { 
    foreach($roleDefinBindings in $roleAssignment.RoleDefinitionBindings)
    {
         Write-Output $roleAssignment.Member.Name
         Write-Output $roleDefinBindings.Name 
    } 

   } 
 } 
} 

Check current member is SharePointGroup/SecurityGroup/User. Reference

if($roleAssignment.Member.PrincipalType -eq Microsoft.SharePoint.Client.Utilities.PrincipalType.SharePointGroup)
{
#SharePointGroup
}
if($roleAssignment.Member.PrincipalType -eq Microsoft.SharePoint.Client.Utilities.PrincipalType.SecurityGroup)
{
#SecurityGroup
}
if($roleAssignment.Member.PrincipalType -eq Microsoft.SharePoint.Client.Utilities.PrincipalType.User)
{
#User
}
5
  • Thanks, it is very close to my need. I am looking for way to display "Group Type" (i.e. Domain Group, SharePoint Group, User)
    – Mark L
    Jul 28, 2017 at 9:49
  • @vishal-m-patil The above does not serve the purpose, though it displays group and permission; it did not display the user for each group. Jul 28, 2017 at 10:38
  • I tested "PrincipalType" is not a member of "$roleAssignment.Member".
    – Mark L
    Jul 31, 2017 at 5:57
  • try to load $roleAssignment & $roleAssignment.Member in context before using it. look at this article Jul 31, 2017 at 6:19
  • Is it supported in SP2010? it returns "New-Object : Cannot find type [Microsoft.SharePoint.Client.ClientContext]"
    – Mark L
    Aug 4, 2017 at 7:40
2

You can use it, you must modify the $ site variable to point to your site collection.

Syntax: <script name>.ps1 | out-file c:\permissions.txt

Here is script

#Get all subsites for site collection
$web = $site.AllWebs

#Loop through each subsite and write permissions

foreach ($web in $web)
{
if (($web.permissions -ne $null) -and ($web.hasuniqueroleassignments -eq "True"))
{
Write-Output "****************************************"
Write-Output "Displaying site permissions for: $web"
$web.permissions | fl member, basepermissions
}
elseif ($web.hasuniqueroleassignments -ne "True")
{
Write-Output "****************************************"
Write-Output "Displaying site permissions for: $web"
"$web inherits permissions from $site"
}

#Loop through each list in each subsite and get permissions

foreach ($list in $web.lists)
{
$unique = $list.hasuniqueroleassignments
if (($list.permissions -ne $null) -and ($unique -eq "True"))
{
Write-Output "****************************************"
Write-Output "Displaying Lists permissions for: $web \ $list"
$list.permissions | fl member, basepermissions
}
elseif ($unique -ne "True") {
Write-Output "$web \ $list inherits permissions from $web"
}
}
}
Write-Host "Finished."
$site.dispose()
$web.dispose()
$unique.dispose()  
0

Below did the job for me with more details.

https://gallery.technet.microsoft.com/office/SharePoint-Permissions-f42ea9db

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.