I have the following PowerShell script that is failing after 30min of execution with an System.outOfMemoryException
$csv = get-content "C:\test\groups.txt"
$result = $csv | foreach-object {
$group=$_
get-QADGroupMember "$_" -PageSize 500 -sizelimit 0 |
select-object sAMAccountName,@{n="GroupName";e={$group}},type
}
$result | export-csv C:\test\groupMembers.csv -Delimiter "|" -notypeinformation
What the script does, is getting the content from the text file groups.txt
which is a list of all groups found in the Active Directory, then for each group, it extracts in csv the group name, member name and member type.
If I am not wrong, the script is processing too much data into memory and fails when the limit is reached, is there a way to tune the script for example to release the memory every time a group is proceeded or something?