Showing posts with label Web Application Policy. Show all posts
Showing posts with label Web Application Policy. Show all posts

Thursday, November 27, 2014

Manage Web Application Policy using SharePoint PowerShell Script

Remove a existing Web Application Policy using SharePoint PowerShell Script

# Get the Web Application Object
$webappobj = Get-SPWebApplication [Web Application URL]

# Return the Web Application policies and find the index of the policy which you would like to delete
$webappobj.Policies

# Put the index value and delete the policy
$webappobj.Policies.Remove([Index])

$webappobj.Update()

# Verify the policies again if it is deleted successfully
$webappobj.Policies

Add a new Web Application Policy using SharePoint PowerShell Script

# Get the Web Application Object
$webappobj = Get-SPWebApplication [Web Application URL]

# Create a policy role object with permission level like FullRead, FullControl etc.
$fullReadPolicyRole = [Microsoft.SharePoint.Administration.SPPolicyRoleType]::FullRead
$policyRole = $webappobj.PolicyRoles.GetSpecialRole($fullReadPolicyRole)

# Add the new web app policy with account name and account description
$policy = $webappobj.Policies.Add("TECHMM\SSWAIN", "Samarendra Swain")

# Bind the policy role to the new web  app policy
$policy.PolicyRoleBindings.Add($policyRole)

$webappobj.Update()