Export User Permissions to HTML using PowerShell in SharePoint Online

Export User Permissions to HTML using PowerShell
InfoPath alternatives for form designing SharePoint

Objective:
In our previous article we learned how to export the result to HTML. In this article I would like to implement the ConvertTo-Html operator to export SharePoint site collection user permissions to html file.

Why we need this?
In SharePoint application world, most often business owner want 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 a right option. This below script export the permission of required user to html.

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

PowerShell Script:

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

The output is as follows:

Export User Permissions to HTML using PowerShell
Export User Permissions to HTML using PowerShell

Hope this helps !!!

Similar SharePoint 2013 Tutorials

About Krishna Vandanapu

I am Krishna.Vandanapu a SharePoint architect working in IT from last 12 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

View all posts by Krishna Vandanapu →

Leave a Reply