title: Public folders remove all permissions for all users
body: <p>I have hundreds of Public folders, and I need to remove all existing user permissions on each folder, then add new permissions for Default and Anonymous.  Some users don't exist, or are disabled.</p>
  
  <p>This is the ps1 file I've written:</p>
  
  <pre><code>param (
    [string] $pf='\Clients'
  )
  $children = Get-PublicFolder -Identity $pf –Recurse
  $children | % {
    $Perm = Get-PublicFolderClientPermission $_.Identity
    $Perm | % {
      Remove-PublicFolderClientPermission -Identity $_.Identity -User $_.User -Confirm:$false
    }
    Remove-PublicFolderClientPermission -Identity $_.Identity -User Default -Confirm:$false
    Add-PublicFolderClientPermission -Identity $_.Identity -User Default -AccessRights Owner
    Remove-PublicFolderClientPermission -Identity $_.Identity -User Anonymous -Confirm:$false
    Add-PublicFolderClientPermission -Identity $_.Identity -User Anonymous -AccessRights Contributor
  }
  </code></pre>
  
  <p>Error is:</p>
  
  <pre>Cannot process argument transformation on parameter 'User'. Cannot convert value
  "Default" to type
  "Microsoft.Exchange.Management.StoreTasks.MailboxFolderUserIdParameter".
  Error: "Cannot convert hashtable to an object of the following type:
  Microsoft.Exchange.Management.StoreTasks.MailboxFolderUserIdParameter.
  Hashtable-to-Object conversion is not supported in restricted language mode or a
  Data section."
      + CategoryInfo          : InvalidData: (:) [Remove-PublicFolderClientPermission], ParameterBindin...mationException
      + FullyQualifiedErrorId : ParameterArgumentTransformationError,Remove-PublicFolderClientPermission
      + PSComputerName        : outlook.office365.com</pre>
  
  <p>This error is for "Default", same thing happened for normal user accounts that exist.  </p>
  
  <p><code>$_.User</code> on the 8th line doesn't parse as a user.  Any thoughts?</p>