Forum Discussion
VidRocksKay
Aug 29, 2022Copper Contributor
Export a combined (from two different sources) result as a CSV using PowerShell
Hi Guys, I have a requirement to fetch Office 365 users based on a CSV file column (Display Name) and finally update the rest of the columns in it (UPN, First Name, Last Name, IsLicensed etc..) ...
- Aug 29, 2022
VidRocksKay I changed your script a little bit 🙂
$Import = Import-Csv D:\temp\users.csv -Delimiter ';' $Total = @() foreach ($item in $Import) { $MS = Get-MsolUser -SearchString $Item.DisplayName $msoluser = [PSCustomObject]@{ 'UserPrincipalName' = $MS.UserPrincipalName 'IsLicensed' = $MS.IsLicensed 'BlockCredential' = $MS.BlockCredential 'FirstName' = $MS.FirstName 'LastName' = $MS.LastName 'ArchiveID' = $item.ArchiveID 'DisplayName' = $item.DisplayName } $Total += $msoluser } $Total | Select-Object DisplayName, ArchiveID, UserPrincipalName, IsLicensed, BlockCredential, FirstName, LastName | Export-Csv -NoTypeInformation "D:\Temp\NewOutput.csv" -Delimiter ';' -Encoding UTF8
Changed it to a pscustomobject and added every item to a Total variable and saved it to a .csv (Used ; as delimiter, for you it could be a , ) You also had a ArchiveName but I didn't see it in your screenshot, so I removed if for testing but you could add it again 🙂
My users.csv file:Displayname; ArchiveID Alex Wilber;1 Allan Deyoung;2
I ran this in my CDX environment for these two users, Excel output:
Aug 30, 2022
Is your question based on the same import-thing as your original question? Perhaps it's better to create a new topic for this 🙂
VidRocksKay
Sep 02, 2022Copper Contributor
Hi Harm_Veenstra
Yes its the same thing. Just that I wanted to combine all 3 steps in to a single script :). I have posted it as a new question here if you can help out - https://techcommunity.microsoft.com/t5/windows-powershell/generating-a-combined-csv-from-multiple-sources-currently-using/m-p/3615909#M5252
Appreciate it ! Thank you
Yes its the same thing. Just that I wanted to combine all 3 steps in to a single script :). I have posted it as a new question here if you can help out - https://techcommunity.microsoft.com/t5/windows-powershell/generating-a-combined-csv-from-multiple-sources-currently-using/m-p/3615909#M5252
Appreciate it ! Thank you