none
PowerShell Script for Permission

    Question

  • Hi,

    I want to export a .csv report for all User Permission details with their group, Permission Level and Site/SubSite. I am using SharePoint Online with O365. I have a script but that gives detail only for Site Collection. How can I get permission report for subsites ?

    Can anyone help me for script?

    Thanks,

    Abhishek

    Thursday, March 30, 2017 4:55 PM

All replies

  • Hi,

    Here is the script

    #Add SharePoint PowerShell SnapIn if not already added
    if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
    }
    
    #Define variables
    $site = Get-SPSite "http://<site collection>"
    
    #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()

    Hope this helps :)

    Saturday, April 1, 2017 5:22 AM
  • This won't work in any case in Office365 due to simple fact that get-spsite is not even a recognized SP Online cmdlet. What the forum poster want is only achievable using CSOM.
    Saturday, April 1, 2017 6:26 AM
  • it's not working.
    Saturday, April 1, 2017 6:37 AM
  • See my previous reply: This won't work in any case in Office365 due to simple fact that get-spsite is not even a recognized SP Online cmdlet. What the forum poster want is only achievable using CSOM.
    Saturday, April 1, 2017 10:03 AM