Forum Discussion
Azure AD join device list export
- Nov 23, 2018
Hi Shubham,
You can get a list of Azure AD joined devices through the Get-MsolDevice cmdlet in Powershell.
https://docs.microsoft.com/en-us/powershell/module/msonline/get-msoldevice?view=azureadps-1.0
The Get-MsolDevice -All -ReturnRegisteredOwners cmdlet will output a list of all devices and their owners which contain the output DeviceTrustType which is the device trust type. The value could be one of the following: Workplace Joined, AzureAD Joined, Domain Joined.
All you need to do is combine this with an export command such as | Export-Csv C:\Temp\LicensedUsers.csv and this should give you the list.AFAIK, there isn't a way to do this through the portal currently.
Best, Chris
Joshua Bines Thanks for this code. I was able to get an export of all of my devices with RegisteredOwnersToString. Any idea how to import this and and filter it even further? Ultimately I want to find all Workplace Joined devices that aren't owned by a particular account (DEM account) and remove them from Azure. My first step is to just filter out those devices.
I've tried importing the csv I exported with your code:
$Device = Import-Csv C:\temp\12345.csv
$Device | ForEach-Object {Get-MsolDevice -all | Where-Object {$Device.DeviceTrustType -eq "Workplace Joined" -and ($Device.RegisteredOwnersToString -eq "account.name@domain.com")}}| Export-CSV -path c:\temp\filtered.csv
I've got a loop that keeps growing the filtered.csv file and it's not filtering out anything.
I'm a Powershell novice so I'm trying to apply PS commands I've used in the past for other things to my current needs.
Thanks for any help.
delvalboyboy I'm glad it helped. If you have the export with the data you need I don't think you need to pull the same data again. I think should work and will be much faster.
Or if your not up for PS... opening the CSV with excel and using the filter option could work just as well if the csv has all the data you require. Good luck! J