Forum Discussion
Kieran_Mees
Apr 04, 2022Copper Contributor
Take CSV with UPNs and add DisplayName, PrimarySMTPAddress and GUID
Hi, I'm currently looking for a way to amend my code Get-Mailbox -Resultsize Unlimited | select DisplayName,PrimarySMTPAddress,UserPrincipalName,GUID| Export-csv C:\O365Users.csv So that th...
- Apr 05, 2022I figured it out.
The script I used is as following:
Import-CSV C:\TestCSV.csv|
ForEach-Object {Get-Mailbox -id $_.UserPrincipalName} |
Select Name,DisplayName,UserPrincipalName,GUID,PrimarySMTPAddress |
export-csv -NoTypeInformation c:\TestCSV2.csv
VasilMichev
Apr 04, 2022MVP
Try something like this:
Import-CSV blabla.csv | % { Get-Mailbox $_.UPN | select DisplayName,PrimarySMTPAddress,UserPrincipalName,GUID }
where you have a CSV file named blabla.csv, with column UPN to designate the user.
Import-CSV blabla.csv | % { Get-Mailbox $_.UPN | select DisplayName,PrimarySMTPAddress,UserPrincipalName,GUID }
where you have a CSV file named blabla.csv, with column UPN to designate the user.
Kieran_Mees
Apr 05, 2022Copper Contributor
VasilMichev Ok that seemed to work, however it grabs those values of everyone on the Exchange. I only want the values for the specific ones from the CSV.
E.g. the server has 20 users, in my CSV I have 10 users I want the GUID, Primary SMTP and display name for.
Additionally, how would I put this all back into the CSV? When I try to export-csv, I get an error because of the $_ variable and when I try putting "$_ Out-File C:\example.csv" the example.csv only has a weird greek symbol which I assume is an error.
- Kieran_MeesApr 05, 2022Copper ContributorI figured it out.
The script I used is as following:
Import-CSV C:\TestCSV.csv|
ForEach-Object {Get-Mailbox -id $_.UserPrincipalName} |
Select Name,DisplayName,UserPrincipalName,GUID,PrimarySMTPAddress |
export-csv -NoTypeInformation c:\TestCSV2.csv