我有一個內存問題,我需要關於powershell的幫助。對於以下代碼:內存不足
function Get-PathPermissions {
param ([Parameter(Mandatory=$true)] [System.String]${Path})
process {
$groups=$null
[email protected]{}
$containers = Get-ChildItem -path $Path -recurse | ? {$_.psIscontainer -eq $true}
if ($containers -eq $null) {break}
foreach ($container in $containers) {
Write-Output "Container: " $container
$accts = (Get-ACL $container.fullname).Access
foreach($acct in $accts) {
$acctsQADObject = Get-QADObject -Identity ([string]$acct.IdentityReference)
if ($acctsQADObject.ObjectClass -contains 'group') {
$Name = $acctsQADObject.Name
$DN = $acctsQADObject.DN
if (!$groups.ContainsKey($Name)) {
Write-Output "Adding $($Name) and $($DN)"
$groups.add($($Name),$($DN))
}
}
}
}
foreach ($key in $groups.GetEnumerator() | Sort-Object Name -descending) {
dumpGroup($key.value)
}
}
}
對於每個$accts
循環,我的記憶會增加。例如,我從1.41 GB開始,它只是繼續攀升1.42,1.43 ... 3.00GB +。這不是對組哈希的添加,因爲只有兩組可以進行測試。每次需要設置$accts = $null
嗎?我認爲每個循環都會造成$accts
以上,摧毀他之前的一個。
任何解決方案嗎? – Kiquenet 2012-08-09 12:17:49