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?
You need to replace $_.User
to $_.User.DisplayName
I know it was published a long time ago, but it is still relevant.
Same solution :
$a= Get-publicFolder \ -recurse -resultsize unlimited
$b= $a | Get-PublicFolderClientPermission
foreach ($pfper in $b) {
write-host $pfper.User.DisplayName $pfper.Identity ; Remove-PublicFolderClientPermission $pfper.Identity -User $pfper.User.DisplayName -Confirm:$false}
Get-PublicFolder \ -Recurse | Add-PublicFolderClientPermission -User Anonymous -AccessRights None
Get-PublicFolder \ -Recurse | Add-PublicFolderClientPermission -User Default -AccessRights None
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.