Powershell - Export-CSV and Append

后端 未结 4 703
心在旅途
心在旅途 2020-12-11 16:36

I have a script such as the following:

$in_file = \"C:\\Data\\Need-Info.csv\"
$out_file = \"C:\\Data\\Need-Info_Updated.csv\"
$list = Import-Csv $in_file 
Fo         


        
4条回答
  •  鱼传尺愫
    2020-12-11 17:12

    Convert the foreach loop into a foreach-object and move the export-csv to outside the outter foreach object so that you can pipe all the objects to the export-csv.

    Something like this (untested):

    $list | ForEach {
    $zID = $_.zID
    ForEach-Object { Get-QADUser -Service 'domain.local' -SearchRoot 'OU=Users,DC=domain,DC=local' -SizeLimit 75000 -LdapFilter "(&(objectCategory=person)(objectClass=user)(PersonzID=$zID))" |
    Select-Object DisplayName,samAccountName,@{Name="zID";expression={$zID}} | 
    
    }
    } |Export-Csv $out_file -NoTypeInformation -Force
    

提交回复
热议问题