Running out of memory

979 views Asked by At

I have a memory problem issue I need help with for powershell. For the following code:

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)
    }
}                
}

For every $accts loop, my memory increases. I start at 1.41 GB for example, and it just keeps climbing 1.42, 1.43 ... 3.00GB+. It is not the adding to the groups hash as there are only two groups seen for testing. Do I need to set $accts = $null every time? I would think each loop would create $accts over, destroying he previous one.

1

There are 1 answers

4
Thomas Lee On

you could try to call the garbage collection after processing each file.