我正在運行下面的腳本,它導致“system.outofmemoryexception”型別的例外被拋出
我相信這是由于 @Results 陣列增長超過分配給 windows shell 的 2gb。有沒有辦法遍歷結果,或者我是否堅持分配更多記憶體(最終可能會很多......)?
$Path = "path to output"
### Get all PF
$publicFolders = Get-PublicFolder "Public Folder Name" -Recurse -resultsize unlimited | Select-Object *
### Array to contain results
$results = @()
###Begin looping through each PF and grab each user/group with AccessRights to that folder
$final = ForEach($pf in $publicFolders){
$perms = Get-PublicFolderClientPermission -Identity $pf.Identity | Where-Object {$_.User -notmatch "Default|Anonymous|S-X-X-XX"}
Foreach($perm in $perms){
$temp = [PSCustomObject]@{
MailFolderName = $pf.Identity
UserWithPerms = $perm.User
AccessRights = $perm | Select-Object -ExpandProperty AccessRights
}
$results = $temp
}
}
$final | Export-Csv $path -NoTypeInformation
我是不是叫錯了樹?
提前致謝。
uj5u.com熱心網友回復:
對外部回圈使用ForEach-Objectcmdlet 而不是foreach(){}回圈陳述句 - 這樣您就可以Export-Csv立即開始通過管道傳輸輸出,而不是將其緩沖在陣列中:
$publicFolders |ForEach-Object {
$pf = $_
$perms = Get-PublicFolderClientPermission -Identity $pf.Identity | Where-Object {$_.User -notmatch "Default|Anonymous|S-X-X-XX"}
Foreach($perm in $perms){
[PSCustomObject]@{
MailFolderName = $pf.Identity
UserWithPerms = $perm.User
AccessRights = $perm | Select-Object -ExpandProperty AccessRights
}
}
} | Export-Csv $path -NoTypeInformation
或者,在列舉每個檔案夾的權限后,將部分結果重繪 到檔案中:
ForEach($pf in $publicFolders){
$perms = Get-PublicFolderClientPermission -Identity $pf.Identity | Where-Object {$_.User -notmatch "Default|Anonymous|S-X-X-XX"}
$results = Foreach($perm in $perms){
[PSCustomObject]@{
MailFolderName = $pf.Identity
UserWithPerms = $perm.User
AccessRights = $perm | Select-Object -ExpandProperty AccessRights
}
}
# flush the buffer before moving to the next set of permissions
$results |Export-Csv $path -NoTypeInformation -Append
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/314081.html
下一篇:我想忽略動態值中的“\”
