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=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
$site = new-object Microsoft.SharePoint.SPSite("https://bobmoss32:9000")

# Get the webapplication

$webapp=$site.WebApplication

# Display the global policies

$webapp.Policies

#Display global policies with RoleBindings

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

# Display the anonymous policy as well

$webapp.Policies.AnonymousPolicy

#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}}