I have the following code abstract:
[pscustomobject]$resultSet = Get-ADObject ...
$users = [System.Collections.ArrayList]@()
$groups = [System.Collections.ArrayList]@()
foreach ($result in $resultSet)
{
if ($result.objectClass -eq "group") {
$null = $groups.Add([pscustomobject]@{
...
}
if ($result.objectClass -eq "user") {
$null = $users.Add([pscustomobject]@{
...
}
}
$groups | Export-Csv ...
$users | Export-Csv ...
Is there a way to improve the performance of the export to individual CSV files?
The Get-ADObject bit takes about 13 seconds (23000 entries), it takes another 5 seconds to build the individual arrays but then takes another 5 minutes to output to the CSV files. I need the output to be split into different files as it’ll be consumed by downstream systems but I’m surprised at how long it’s taking.
Any advice on improving the Export-Csv portion of the code?
Thanks.