Get Information Rights Management for entire farm using PowerShell Scripts


Working on Migration Project from SharePoint On-premises to SharePoint – online. Don’t miss the IRM information of your existing SharePoint applications. IRM is very important feature of SharePoint and matters a lot for organization governance policy.

I will further post how to configure Infromation Rights Management in Office 365. This article will be helpful to retract IRM configuration of existing farm.

Please find below PowerShell for further reference.

$ver = $host | select version
if($Ver.version.major -gt 1) {$Host.Runspace.ThreadOptions = “ReuseThread”}
if(!(Get-PSSnapin Microsoft.SharePoint.PowerShell -ea 0))
{
Add-PSSnapin Microsoft.SharePoint.PowerShell
}
cls
try{
#Specify a directory for which to log the results
$0 = $MyInvocation.MyCommand.Definition
$dp0 = [System.IO.Path]::GetDirectoryName($0)
$LoggingDirectory = $dp0
$logFile=$(“$dp0\Logs\EntireFarm_IRM_LogInformation.txt”)
$ExecutionStartTime = (Get-Date -UFormat “%Y-%m-%d_%I:%M:%S %p”).tostring()
Write “Script started at” $ExecutionStartTime >> $logFile
Write-Host “Script started at” $ExecutionStartTime
$PageLayout_Webparts_DetailsCSV =@()
#Create a variable based on the current date and time
$StartTime = (Get-Date -UFormat “%Y-%m-%d_%I-%M-%S %p”).tostring()

#Dynamically generate the log file name
$Filename = “$LoggingDirectory\Result\EntireFarm_IRM_Details_” +$StartTime +”.csv”

#Create Column Headers of csv
#’WebURL,List,Flag,FolderURL,FolderName’ | Out-File $Filename -Append;

$webapplist = Get-SPWebApplication
foreach($webappUrl in $webapplist){
try{
#Specify the Web Application to be targeted
$WebApplicationURL = $webappUrl.Url

#Write “`r`n web application URL” $WebApplicationURL “is being investigated” >> $logFile

#Get all sites within each of the specified web application
$AllSites = Get-SPSite -WebApplication $WebApplicationURL -Limit All
#$AllSites = Get-SPSite $WebApplicationURL -Limit All

foreach($Site in $AllSites){
Write “`r`nInside Site'” + $Site.Url >> $logFile
try{
#Return all webs in each site collection returned to the AllWebs variable
$AllWebs = $Site.Allwebs

#Perform some actions against each web retrieved from the current target site collection
foreach($Web in $AllWebs){
try{
$AllList = $Web.Lists
foreach($List in $AllList){
#Write-Host $List.Title ‘|’ $List.IrmEnabled
if($List.IrmEnabled){
Write “============================================================================” >> $logFile
Write $List.InformationRightsManagementSettings.PolicyTitle >> $logFile
Write $List.InformationRightsManagementSettings.PolicyDescription >> $logFile
Write $List.IrmReject >> $logFile
write $List.IrmExpire >> $logFile
Write $List.InformationRightsManagementSettings.DocumentLibraryProtectionExpireDate >> $logFile
Write $List.InformationRightsManagementSettings.DisableDocumentBrowserView >> $logFile
Write $List.InformationRightsManagementSettings.AllowPrint >> $logFile
Write $List.InformationRightsManagementSettings.AllowScript >> $logFile
Write $List.InformationRightsManagementSettings.AllowWriteCopy >> $logFile
Write $List.InformationRightsManagementSettings.EnableDocumentAccessExpire >> $logFile
Write $List.InformationRightsManagementSettings.DocumentAccessExpireDays >> $logFile
Write $List.InformationRightsManagementSettings.EnableLicenseCacheExpire >> $logFile
Write $List.InformationRightsManagementSettings.EnableGroupProtection >> $logFile
Write $List.InformationRightsManagementSettings.GroupName >> $logFile
Write “============================================================================” >> $logFile

$PageLayout_Webparts_DetailsCSV+=New-Object PSObject -Property @{
WebURL=$Site.Url;
WebTitle=$Web.Title;
ListName=$List.Title;
ListURL=$List.DefaultViewUrl;
IrmEnabled=$List.IrmEnabled;
PolicyTitle=$List.InformationRightsManagementSettings.PolicyTitle;
PolicyDescription=$List.InformationRightsManagementSettings.PolicyDescription;
IrmReject=$List.IrmReject;
IrmExpire=$List.IrmExpire;
DocumentLibraryProtectionExpireDate = $List.InformationRightsManagementSettings.DocumentLibraryProtectionExpireDate;
DisableDocumentBrowserView=$List.InformationRightsManagementSettings.DisableDocumentBrowserView;
AllowPrint=$List.InformationRightsManagementSettings.AllowPrint;
AllowScript=$List.InformationRightsManagementSettings.AllowScript;
AllowWriteCopy=$List.InformationRightsManagementSettings.AllowWriteCopy;
EnableDocumentAccessExpire=$List.InformationRightsManagementSettings.EnableDocumentAccessExpire;
DocumentAccessExpireDays=$List.InformationRightsManagementSettings.DocumentAccessExpireDays;
EnableLicenseCacheExpire=$List.InformationRightsManagementSettings.EnableLicenseCacheExpire;
EnableGroupProtection=$List.InformationRightsManagementSettings.EnableGroupProtection;
GroupName=$List.InformationRightsManagementSettings.GroupName}

}
}
$Web.Dispose()
}
catch [Exception]{
Write $_.Exception|format-list -force >>$logFile
Write-Host -f red $_.Exception|format-list -force
}
finally{
if($Web){
$Web.Dispose()
}
}
}
$Site.Dispose()
}
catch [Exception]{
Write $_.Exception|format-list -force >>$logFile
Write-Host -f red $_.Exception|format-list -force
}
finally{
if($Site){
$Site.Dispose()
}
}
}

}
catch [Exception]{
Write $_.Exception|format-list -force >>$logFile
Write-Host -f red $_.Exception|format-list -force
}

}
$PageLayout_Webparts_DetailsCSV | Export-CSV -path $Filename -notype


}
catch [Exception]{
Write $_.Exception|format-list -force >>$logFile
Write-Host -f red $_.Exception|format-list -force
}
$EndTime = (Get-Date -UFormat “%Y-%m-%d_%I:%M:%S %p”).tostring()
Write “Script stopped at” $EndTime >> $logFile
Write-Host “Script stopped at” $EndTime

Check out Best Alternative to InfoPath -> Try Now

You May Also like the Following SharePoint Online Tutorials:

About Sambita Rath

I have 9 years of exprience into SharePoint implementation, architecture, Administrator, development and Training.Designing Information Architecture in SharePoint 2007, 2010,2013 and Office 365.

View all posts by Sambita Rath →