IRM enabling using PowerShell on SP online list


Here’s my script to set IRM settings in SharePoint online library.

$site = “https://Domain.sharepoint.com/sites/****”
$Context = Get-ClientContext $Username $password $site
$list = $Context.Web.Lists
$context.Load($list)
$context.ExecuteQuery()
Foreach($lists in $list)
{
if($lists.BaseType -eq “DocumentLibrary” -and $lists.Hidden -eq $false)
{
write-host $lists
set-SPOList -ListName $lists
$lists.IrmEnabled =$true
$lists.InformationRightsManagementSettings.PolicyTitle = “RMSDefaultPolicy”
$lists.InformationRightsManagementSettings.PolicyDescription = “Default RMS Policy”
$lists.IrmReject = $true
write-host “hi i am executing”
$lists.InformationRightsManagementSettings.AllowPrint = $true
$lists.InformationRightsManagementSettings.EnableLicenseCacheExpire = $true
$lists.InformationRightsManagementSettings.LicenseCacheExpireDays = “8”
$lists.Update()
$context.ExecuteQuery()
write-Host $lists.Title + “hi”
}

}

References:

https://thesharepointfarm.com/2013/07/using-powershell-to-manage-sharepoint-information-rights-management-settings/

Add user or group to web application user policy


Below script to add a group to full control access to all the web-applications in SharePoint farm.

PowerShell
$userOrGroup = "domain\ROL-G-All-SharePointAdmin-Admin" 
$displayName = "SharePoint Team"
Get-SPWebApplication | foreach { 
$webApp = $_ 
$policy = $webApp.Policies.Add($userOrGroup, $displayName) 
$policyRole = $webApp.PolicyRoles.GetSpecialRole([Microsoft.SharePoint.Administration.SPPolicyRoleType]::FullControl) 
$policy.PolicyRoleBindings.Add($policyRole) 
$webApp.Update() 
}

Add user or group to web application user policy


Below script to add a group to full control access to all the web-applications in SharePoint farm.
$userOrGroup = "domainROL-G-All-SharePointAdmin-Admin" 
$displayName = "SharePoint Team"

Get-SPWebApplication | foreach { 
    $webApp = $_ 
    $policy = $webApp.Policies.Add($userOrGroup, $displayName) 
    $policyRole = $webApp.PolicyRoles.GetSpecialRole([Microsoft.SharePoint.Administration.SPPolicyRoleType]::FullControl) 
    $policy.PolicyRoleBindings.Add($policyRole) 

    $webApp.Update() 
}
Get-SPWebApplication | foreach { 
    $webApp = $_ 
    $policy = $webApp.Policies.Add($userOrGroup, $displayName) 
    $policyRole = $webApp.PolicyRoles.GetSpecialRole([Microsoft.SharePoint.Administration.SPPolicyRoleType]::FullRead) 
    $policy.PolicyRoleBindings.Add($policyRole) 
    $webApp.Update() 
}

 

Change or rename the subsite URL


I can’t rename a URL of a site (using the Site Settings>Title,Description and Icon) I received an error “The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator”

None of the lists in the subsite exceeds the list view threshold item limits.  But when the same operation is attempted with farm admin account is succeeded as that account default is 20000 anyway. So it seems the total items in that site is adding up for this action and not allowing the rename of url.

Two options :

  • Find and increase the LVT.
  • Alternatively use ‘farm account’ to rename on site or use powershell to update (Get-SPWeb http://portal/subsite | Set-SPWeb -RelativeUrl newsubsitename)  in either case the underlying account uses List View Threshold for auditors and administrators which has higher limits of LVT so it could succeed.

Find All InfoPath Form Libraries and lists in SharePoint


As part of the cleanup activity one of the SharePoint analyst requested a report listing all the forms libraries and lists as well with document count and last modified date. Finding lists with forms enabled was different used SharePoint manager to search and query for the property which separates lists with and without forms but no luck.

Then I found the following property from one of the blog and married up the script with Rajack’s script to produce a script works for me.

 

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null
 
#Get the web application
Write-Host "Enter the Web Application URL:"
$WebAppURL= Read-Host
$SiteColletion = Get-SPSite($WebAppURL)
$WebApp = $SiteColletion.WebApplication
 
#Write the CSV header
"Site Collection `t Site `t List Name `t List Url `t Docs Count `t Last Modified `t Form Template" > InfoPathLibs.csv
 
#Loop through all site collections of the web app
    foreach ($site in $WebApp.Sites)
    {
       # get the collection of webs
       foreach($web in $site.AllWebs)
        {
            write-host "Scaning Site" $web.title "@" $web.URL
               foreach($list in $web.lists)
               {
                   if( $list.BaseType -eq "DocumentLibrary" -and $list.BaseTemplate -eq "XMLForm")
                    {
                    $listModDate = $list.LastItemModifiedDate.ToShortDateString()
                    $listTemplate = $list.ServerRelativeDocumentTemplateUrl
                    
       #Write data to CSV File
                   $site.RootWeb.Title +"`t" + $web.Title +"`t" + $list.title +"`t" + $Web.Url + "/" + $List.RootFolder.Url  +"`t" + $list.ItemCount +"`t" + $listModDate +"`t"  + $listTemplate >> InfoPathLibs.csv
                }
                elseif ($list.ContentTypes[0].ResourceFolder.Properties["_ipfs_infopathenabled"])
                {
                    $listModDate = $list.LastItemModifiedDate.ToShortDateString()
                    $listTemplate = $list.ServerRelativeDocumentTemplateUrl
                    #Write data to CSV File
                   $site.RootWeb.Title +"`t" + $web.Title +"`t" + $list.title +"`t" + $Web.Url + "/" + $List.RootFolder.Url  +"`t" + $list.ItemCount +"`t" + $listModDate +"`t"  + $listTemplate >> InfoPathLibs.csv
                }
             
               }
        }
    }
 
#Dispose of the site object
$siteColletion.Dispose()
Write-host  "Report Generated at same path of the powershell script InfoPathLibs.csv" -foregroundcolor green

The following report looks like:

In the below report which ever list does not have a form template implies its a list and all others are document libraries.

report

 

Delete duplicate fields in a sharepoint list based on internal name


I have a similar issue where a content and structure migration created duplicate fields and had to delete fields based on internal name

My code:

$web = Get-SPWeb https://myWeb
$list = $web.Lists["Technical"]
$field = $list.Fields |?{$_.InternalName -eq "InternalNameofthefield"}
$field.ReadOnlyField = $false
$field.AllowDeletion = $true
$field.Sealed = $false
#if I dont update prior I can't delete - on sharepoint 2010 so update command first.
$field.update()
$field.Delete()
$list.Update()
$web.Dispose()

 

Script to find sharepoint group members across sites


The below is a script to look for a group and group members across sites in the SharePoint farm.

You can customize it for site collection and web apps along with export columns.

$sites = Get-SPWebApplication P_Teams" | Get-SPSite -limit all
"Site Collection`t Group`t User Name`t User Login" | out-file groupmembersreport.csv
foreach($site in $sites)
{
	$webs = $site.allwebs
    foreach($web in $webs)
   {
    if($web.hasuniqueroleassignments)
    {
    $group = $web.Groups |?{$_.Name -like "*power*"}
    # you can also filter by exact group name { $_.Name -eq "Power Users"} or look for word in a group
	foreach($user in $group.Users)
		{	
		"$($web.url) `t $($group.Name) `t $($user.displayname) `t $($user) " | out-file groupmembersreport.csv -append
		}
    }
  }
$site.Dispose()

}

 

 

PowerShell Script – list all SharePoint group members


A quick script to query  site collections in a web application for SharePoint group and list all the members of that group and export into an CSV file. In the below example I am looking for “Power Users” group and list all the members of that group

$sites = Get-SPWebApplication http://intranet.contoso.com | Get-SPSite -limit all
"Site Collection`t Group`t User Name`t User Login" | out-file groupmembersreport.csv
foreach($site in $sites)
{
	$sitegroup = $site.RootWeb.SiteGroups |?{$_.Name -EQ "Power Users"}
	foreach($user in $sitegroup.Users)
		{	
		"$($site.url) `t $($sitegroup.Name) `t $($user.displayname) `t $($user) " | out-file groupmembersreport.csv -append
		}
$site.Dispose()
}

If you are interested in querying all the groups in the site collections and list all the members

# if you want to query all the site collections and its groups members then un comment line 4 and comment line 5
# $sites = get-spsite -limit All
$sites = Get-SPWebApplication http://intranet.contoso.com | Get-SPSite -limit all
"Site Collection`t Group`t User Name`t User Login" | out-file groupmembersreport.csv
foreach($site in $sites)
{
	foreach($sitegroup in $site.RootWeb.SiteGroups)
        {
	  foreach($user in $sitegroup.Users)
	 	{	
		"$($site.url) `t $($sitegroup.Name) `t $($user.displayname) `t $($user) " | out-file groupmembersreport.csv -append
		}
          }
$site.Dispose()
}

You can also write in a single line if you quickly want to query for a single site collection

Get-Spweb http://intranet.contoso.com | Select -ExpandProperty SiteGroups | Where {$_.Name -EQ "Power Users"} | Select -ExpandProperty Users | Select Name, userlogin, Email

 

Docave 5 Agent does not start


Issue:
I am receiving the following error when attempting to start the DocAve 5 service on the server.
This issue is specifically for servers which has CRL check issues( no intenet connection or certificate servers not configured)

The DocAve Communication service failed to start due to the following error:
The service did not respond to the start or control request in a timely fashion.

and

A timeout was reached (30000 milliseconds) while waiting for the DocAve Communication service to connect.

Solution:
The solution is to add a configuration file to the Docave Agent bin folder.
e.g: c:program filesAvePointdocAve6Agentbin

Copy below lines into a file named: DocAveAVPCService.exe.config

<?xml version="1.0"?>
<configuration>
  <runtime >
    <generatePublisherEvidence enabled="false"/>
  </runtime>
</configuration>

This is only effective for Docave 5 agent. Lookout for another post on docave 6 agent steps.