How to export user permission in SharePoint using PowerShell

This PowerShell SharePoint tutorial, we will discuss how to export user permission in SharePoint 2013/2016/Online using PowerShell.

Here I will show you, how to implement the ConvertTo-Html operator to export SharePoint site collection user permissions to HTML file. You can check my previous posts on Create HTML Reports using PowerShell.

In the SharePoint application world, most often business owner wants to review the permission in their site collection. If we have to generate the script and copy-paste the result set or redirect the output to txt file will not be the right option. The below script export the permission of the required user to Html.

Export user permission in SharePoint 2013 using PowerShell

In this PowerShell script, we are fetching the permissions of the users “Sai Vandanapu” and “Kethana Vandanapu” across the site collection.

Add-PSSnapin Microsoft.SharePoint.PowerShell
Start-SPAssignment Global
$Header = @"
<style>
table{
font-family:"Segoe UI";
border-collapse: collapse;
border: 2px solid;
border-color:black;
width: 60%;
margin-left:20px;
}
th{
padding-top:4px;
padding-bottom:4px;
text-align:left;
background-color:yellow;
color:black;
border-collapse: collapse;
border: 2px solid;
border-color:black;
}
td{
padding-top:4px;
padding-bottom:4px;
text-align:left;
color:black;
border-collapse: collapse;
border: 1px solid;
border-color:black;
}
</style>

<title>SharePoint Site User Permissions</title>
"@
function GetPerms {
$PermsColl = @([psobject])
$site = Get-SPSite http://sharepoint13:12345
#Reading through all the sites in the site collection
$site | Get-SPWeb -Limit all | ForEach-Object {
#Fetching the RoleAssignments collection
foreach ($roleAssignment in $_.RoleAssignments) {
#Ensuring that the permissions collection is not null
if (-not [string]::IsNullOrEmpty($roleAssignment.Member.Xml)) {
foreach ($roleDefinBindings in $roleAssignment.RoleDefinitionBindings) {
#Creating property collection
$props = @{'SiteName'= $_.Title
'Permissions' = $roleDefinBindings.Name
'User/GroupName' = $roleAssignment.Member.Name
}
#Validating the user name with Sai & Kethana
if ($roleAssignment.Member.Name -eq 'Sai Vandanapu' -or $roleAssignment.Member.Name -eq 'Kethana Vandanapu') {
$PermsColl += New-Object -TypeName PSObject -Property $props
}
}
}
}
}
Write-Output $PermsColl
}
#Calling GetPerms function and selecting the columns from the result set and adding "SharePoint Site User Permissions" as Precontent header
$result = GetPerms | Select SiteName, User/GroupName, Permissions | ConvertTo-Html -Fragment -PreContent '<h2>SharePoint Site User Permissions</h2>'
#Converting the result set to HTML
ConvertTo-Html -Body "$result" -Head $Header | Out-File UserPermisssions.html
Stop-SPAssignment Global

Below is how you can see the SharePoint user permissions of the user.

export user permissions sharepoint 2013 using powershell

You may like the following PowerShell SharePoint tutorials:

In this SharePoint tutorial, we learned how to export user permissions in SharePoint 2013/2016 using PowerShell.

  • >