1

In Sharepoint, I have a list with custom permissions:

I want to create a powershell script that can loop through the permissions, and get two things, 1 is the permission name, and the other is the name, weather it is a person or group.

I have this:

$lists = $spWeb.Lists | Where-Object {$_.Title.StartsWith('custom_')}
$listCount = $lists.Count


write-host ("Found {0} lists..." -f $listCount)
foreach ($list in $lists) {
    $collRoleDefinitions = $list.RoleDefinitions;
    $collRoleAssignments = $list.RoleAssignments;

    #write-host $collRoleDefinitions
    $assignments = $collRoleAssignments


    foreach($role in $assignments) {
       write-host $role
    }
}

but I don't know how to get the permission name and user account. For the user account I think this might work

$role.Member; 

but unsure about the permission name. Basically I want to get things like "Contribute" or "Full Control".

Does anyone know?

Thanks

1

You can try following script:

Add-PSSnapin Microsoft.SharePoint.PowerShell
$WebUrl = Read-Host 'Please input URL address of target web'
$Web = Get-SPWeb $WebUrl
$ListName = Read-Host 'Please input list name'
$List = $web.Lists[$ListName]

$Unique = $List.hasuniqueroleassignments 

if (($List.permissions -ne $null) -and ($Unique -eq "True")) 
{
  Write-Output "---------------------"
  Write-Output "List permission is: "
  $List.permissions | fl member, basepermissions 
}
elseif ($Unique -ne "True") { 
  Write-Output "Inherits permissions from $Web" 
} 

Write-Host "----------------------" 

$web.dispose()

pause 
0

I tried the following code to get the members and permissions level name for a specific list based on RoleAssignments and Member as the following

$web = Get-SPWeb http://epm/workflow
$list = $web.Lists["listview"]
$list.RoleAssignments | Format-List member, roledefinitionbindings

[Output]

enter image description here

Also, check how to get the members and permissions details based on BasePermissions and Member as the following

$web = Get-SPWeb http://epm/workflow
$list = $web.Lists["listview"]
$list.permissions | Format-list member, basepermissions

[OutPut]

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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