Remove SharePoint Web Application Policy using PowerShell
Requirement: Remove Web Application Policy using PowerShell
How to remove a web application Policy 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 “User Policy” button from the ribbon.
- Now, from the “Policy for Web Application” page, Select the user or group to remove and click on “Delete Selected Users” link
- Confirm the prompt once to remove select accounts from web application Policy.
PowerShell to Remove a Web Application Policy in SharePoint:
You can use PowerShell to manage your SharePoint web application policies. In this blog post, we will show you 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"
To Add a web application policy in SharePoint, use this PowerShell script: SharePoint PowerShell to Add Web Application User Policy