Powershell Azure Active Directory - Need Numbers from Names of Devices

Ok gang,

I have a CSV of Device Names in Azure AD, I want to get a list of DeviceID or ObjectId for each of the names on the list.

I have tried the following
$CHGList = Import-Csv -path C:\Users\username\desktop\CHGList.csv

get-msoldevice -name $CHGList | Select-Object ObjectID | Export-CSV -Path "C:\Users\username\desktop\AzureDeviceID.csv"

I have tried piping over results and running it that way
I have tried changing the Custom Object  to a String
I have tried

$CHGList = Import-Csv -path C:\Users\username\desktop\CHGList.csv
$Modification = $null
$Modification = $CHGList -join ","
get-msoldevice -name $Modification | Select-Object ObjectID | Export-CSV -Path "C:\Users\username\desktop\AzureDeviceID.csv"

I've looked at trying to loop through the CSV file and it's making no sense.

Can I get some help?

Thanks all for your time.
Chris BushSr Systems EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vasil Michev (MVP)Commented:
Assuming you have a column "Name" in the CSV file, try this:

Import-Csv .\CHGList.csv | % {Get-MsolDevice -Name $_.Name | select ObjectId,DeviceId}

Open in new window

If everything runs OK, add the Export-CSV part at the end.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Chris BushSr Systems EngineerAuthor Commented:
That did it. Thank you SO much!
Vasil Michev (MVP)Commented:
No worries, PowerShell is not that hard when you get the hang of it :) Dont forget to mark the answer.
Vasil Michev (MVP)Commented:
If you feel this question wasn't answered or should be closed differently, post an objection. The moderators will review all objections and close it as they feel fit.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.