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.
This is the ps1 file I've written:
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
}
Error is:
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
This error is for "Default", same thing happened for normal user accounts that exist.
$_.User
on the 8th line doesn't parse as a user. Any thoughts?