简体   繁体   中英

Cannot get information from Get-ADUser to output to CSV

I have a SUPER simple query of Get-ADUser select mail that I need to output to CSV. The query fetches the information that I am looking for and prints to screen but when I attempt to use the Export-Csv OR Out-File cmdlets it creates a blank document.

$Users = Import-Csv C:\users\bob\Desktop\Administrator.csv

foreach ($User in $Users) {
    $User = $User.UserName

    Get-ADUser $User -Properties * |
        Select mail |
        Export-Csv -Path C:\Users\miker99a\Desktop\DiscoveryED.csv
}

Im a chucklehead. The answer is -append, I was overwriting the entries as the script ran

$Users = Import-Csv C:\users\bob\Desktop\Administrator.csv

foreach ($User in $Users) {

    $User = $User.UserName

Get-ADUser $User -Properties * | Select mail | Export-Csv -Path C:\Users\miker99a\Desktop\DiscoveryED.csv -Append


 } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM