Remove SharePoint Web Application Policy using PowerShell
Requirement: Remove Web Application Policy using PowerShell.
How to remove a web application Policy in SharePoint?
In SharePoint, user policies can be applied at the web application level to control access to resources for specific users or groups. PowerShell and Central Admin provide an easier way to manage user policies for web applications in SharePoint.
To remove a user or group from SharePoint web application Policy, follow these steps:
- Login to SharePoint Central Administration Site.
- Application Management >> Manage Web Applications.
- Select the appropriate web application from the list >> Click on the “User Policy” button from the ribbon.Â
- Now, from the “Policy for Web Application” page, Select the user or group to remove and click the “Delete Selected Users” link.
- Confirm the prompt once to remove select accounts from the web application Policy.
PowerShell to Remove a Web Application Policy in SharePoint:
You can use PowerShell to manage your SharePoint web application policies. Let’s see how to remove a web application policy using PowerShell.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
Function Remove-WebAppPolicy($WebAppURL, $Account)
{
Try {
Write-host "Removing Account '$Account' from the Web Application '$WebAppURL'..." -f yellow
#Get the web application
$WebApp = Get-SPWebApplication $WebAppURL -EA SilentlyContinue
#Check if web application Exists
if ($WebApp -eq $null)
{
$ErrorMsg = "Web Application " + $WebAppURL + " not found!"
Throw $ErrorMsg
}
#PowerShell to delete a web application policy in SharePoint
$Policy = $webApp.Policies.Remove($Account)
$WebApp.Update()
Write-host "Web Application Policy Removed Successfully! " -f green
}
Catch {
Write-host -f Red "Error Deleting Web Application Policy:" $_.Exception.Message
}
}
#Call the function to remove web application Policy
Remove-WebAppPolicy -WebAppURL "https://intranet.crescent.com/" -Account "i:0#.w|crescent\salaudeen"
By following the steps outlined in this article, you can easily remove a user or group from the user policy of a web application in SharePoint using PowerShell. To Add a web application policy in SharePoint, use this PowerShell script: SharePoint PowerShell to Add Web Application User Policy