Forum Discussion
SS9911
Sep 07, 2023Copper Contributor
Get users from CSV, foreach user, get country, name, etc., then Export
 Hi!  I have a problem with PS query. I have a CSV file with +1000 userprincipalname. Id like to export that UPN and for each user get info like  userprincipalname, title, country, department, enabled...
LainRobertson
Sep 07, 2023Silver Contributor
Hi.
If your CSV has neither headers nor delimited columns, then it's just a text file and not a CSV. Though at the end you say "my Excel", and Excel (.xlsx file extension) is a whole different discussion.
Assuming Excel has nothing to do with this, then you can get what you want with a simple script.
Input file
Example
Get-Content -Path "D:\Data\Temp\Forum\myInputFile.csv" |
    ForEach-Object {
        Get-ADUser -Filter { (userPrincipalName -eq $_) } -Properties country, department, enabled, title, userPrincipalName
    } |
        Select-Object -Property userPrincipalName, enabled, title, department |
            Export-Csv -NoTypeInformation -Path "D:\Data\Temp\Forum\myExportFile.csv";
Output file
Cheers,
Lain