我有数百个公用文件夹,我需要删除每个文件夹上的所有现有用户权限,然后为Default和Anonymous添加新权限。某些用户不存在或被禁用。
这是我写的ps1文件:
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
}
错误是:
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
此错误适用于“默认”,对于存在的普通用户帐户也是如此。
第8行的 $_.User
不会解析为用户。有什么想法吗?
答案 0 :(得分:1)
您需要将$_.User
替换为$_.User.DisplayName
我知道它很久以前就出版了,但它仍然具有相关性。
相同的解决方案:
$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