我有一个内存问题,我需要有关 powershell 的帮助。对于以下代码:
function Get-PathPermissions {
param ( [Parameter(Mandatory=$true)] [System.String]${Path} )
process {
$groups=$null
$groups=@{}
$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
,破坏他之前的循环。