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.
You may like following PowerShell SharePoint tutorials:
- PowerShell out gridview in SharePoint 2013/2016
- Delete Corrupted Service Applications in SharePoint 2013
- SharePoint 2013/2016 PowerShell Script Examples
- Get SharePoint Online Site and List Templates using PowerShell
- Get SharePoint 2013 Server Disk Space using PowerShell
- Get Content DataBase Size Using PowerShell in SharePoint 2013
- SharePoint 2013 Create Site Column and Content Types Using PowerShell
- Change list or library URL in SharePoint 2013/2016
- Create Site Collection and Subsite in SharePoint Online using PowerShell
- PowerShell to clean up user information in SharePoint 2013/2016
- PowerShell recursive function example
- Create List or Document Library using PowerShell in SharePoint Online
This SharePoint tutorial, we learned how to export user permissions in SharePoint 2013/2016 using PowerShell.
I am Krishna.Vandanapu a SharePoint architect working in IT from last 13+ years, I worked in SharePoint 2007, 2010, 2013, 2016 and Office 365. I have extensive hands on experience in customizing SharePoint sites from end to end. Expertise in SharePoint migration tools like Sharegate, Doc Ave and Metalogix. Migrated SharePoint sites from SharePoint 2007 to 2010 and 2010 to 2013 several times seamlessly. Implementing CSOM with Microsoft best practices. Spent quality time in configuring SharePoint application services like User Profile, Search, Managed Meta data services etc. Now exploring SharePoint Framework and SharePoint 2019
Could you do this for folders in a single document library?