Tuesday, April 9, 2013

Add Web Application User Policy using PowerShell in SharePoint

PowerShell code snippet to Add new user in web application policy:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$WebAppURL = "http://sharepoint.crescent.com"
$UserID = "Global\EricConnell"
$UserDisplayName = "Global CIO"

#Get the Web Application
$WebApp = Get-spwebapplication $WebAppURL

#Convert the UserID to Claims - If your Web App is claims based!!!
 $UserAccount = (New-SPClaimsPrincipal -identity $UserID -identitytype 1).ToEncodedString()

#Crate FULL Access Web Application User Policy
$ZonePolicies = $WebApp.ZonePolicies("Default")
#Add sharepoint 2010 web application user policy with powershell
$Policy = $ZonePolicies.Add($UserAccount,$UserDisplayName)

Write-Host "Web Application Policy for $($UserDisplayName) has been Granted!"
GetSpecialRole() function in SharePoint 2010 can take enumerations from : [Microsoft.SharePoint.Administration.SPPolicyRoleType], Such as: FullControl, FullRead, etc.

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...