Link to home
Start Free TrialLog in
Avatar of sirbounty
sirbountyFlag for United States of America

asked on

Creating Distribution Groups through powershell

I have a script that creates a distribution group.
Before I create the group, I create a list of valid users - i.e. those that don't throw an exception that they were not found in the directory (Cannot find an object with identity: 'xxxxxx' under: 'DC=xxxxx,DC=xxxxxx,DC=com'.)

So I'm populating a list of valid members and a list of invalid members, to notify the customer of the ones that failed.

This has been working great on small lists, but now that I've tested one with 19k items, (only about 12k are valid) it throws an OutOfMemoryException:
Exception of type 'System.OutOfMemoryException' was thrown.
    + CategoryInfo          : OperationStopped: (:) [], OutOfMemoryException
    + FullyQualifiedErrorId : System.OutOfMemoryException


Then, shortly after, my 'user not found exception' seems to change to:
A call to SSPI failed, see inner exception.

What's going on and how I can solve this?

Code snippet:

import-csv $file | Select-Object -ExpandProperty $header | ForEach-Object { $_.trim() } |  ForEach-Object {
            try {
                $members += @(Get-ADUser $_ -ErrorAction SilentlyContinue)
            } catch {
                $nonMembers += $_.exception.message
            }
        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gary Dewrell
Gary Dewrell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of M A
Avatar of sirbounty

ASKER

Ah, wasn't aware of that gdewrell - I'll give it a try on my next run... thanks!
thanks MAS - I'll check on those links as well.