How to display Web Application Policies with Powershell

I had to create this script to troubleshoot the anonymous permission setting problem and I though it might come handy for you.

Let’s start with the usual SPSite creation

[Reflection.Assembly]::Load("Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
$site = new-object Microsoft.SharePoint.SPSite("http://bobmoss32:9000")

# Get the webapplication


# Display the global policies


#Display global policies with RoleBindings

foreach ($zonepol in $webapp.Policies) {$zonepol;$zonepol.PolicyRoleBindings}

# Display the anonymous policy as well


#Get the IIS zones and get the policies for each zone as well

foreach ($zone in $webapp.IisSettings.Keys) {$zone; $webapp.ZonePolicies($zone)}

#Display the RoleBindings as well with the per zone AnonymousPolicy

foreach ($zone in $webapp.IisSettings.Keys) {$zone; foreach ($zonepol in $webapp.ZonePolicies($zone)) {$zonepol;$zonepol.PolicyRoleBindings;$zonepol.AnonymousPolicy}}