Step 1, install AzureAD module if you have done this yet.
Type “PowerShell” from the start menu >> Right-click on Windows PowerShell and choose “Run as administrator”
Type “Install-Module AzureAD” and hit Enter.
You’ll be asked to confirm the installation from the PSGallery. Type “A” to select “Yes to All” and hit the Enter key.
To update the existing Azure AD module to the latest version, run the following command as admin:
Update-Module -Name AzureAD
Step 2: to run this script, you will need to install the MSOnline module as well.
For some backward compatibility, If you need the V1 of the Azure AD PowerShell module (AKA: MSOnline), here is how to install and connect to Microsoft Azure Active Directory with the Connect-MSOLService cmdlet:
Install-Module -Name MSOnline
Step 3: Run the below script.
You can download this text file and change its file type to PS1. Or copy the below scripts to make your own piece.
Connect-MsolService
$TStamp = $(get-date -f MM-dd-yyyy_HH_mm_ss)
$Devices = Get-MsolDevice -All -ReturnRegisteredOwners -IncludeSystemManagedDevices
$DeviceInfo = @()
foreach ($Device in $Devices) {
$DeviceInfo += [PSCustomObject]@{
"DisplayName" = $Device.DisplayName
"DeviceTrustType" = $Device.DeviceTrustType
"DeviceTrustLevel" = $Device.DeviceTrustLevel
"DeviceOS" = $Device.DeviceOsType
"DeviceVersion" = $Device.DeviceOsVersion
"RegisteredOwner" = $($Device.RegisteredOwners)
"LastLogon" = $Device.ApproximateLastLogonTimestamp
"LastDirSync" = $Device.LastDirSyncTime
"DeviceID" = $Device.DeviceId
"ObjectID" = $Device.ObjectId
}
}
$DeviceInfo | Export-Csv -NoTypeInformation .\"Device Info - $TStamp.csv"
Ref: https://techcommunity.microsoft.com/t5/microsoft-defender-for-cloud/azure-ad-join-device-list-export/m-p/290550