Do with what you will, use the handy # Write-Host ($SpecificVar | Format-List | Out-String) # to see what is available.
$tenantId = 'xxxxxxxxxxxx' # You Tenant ID
$appId = 'xxxxxxxxxx' # Application (client) ID
$appSecret = 'xxxxxxxxxxx' #Value
$body = @{
grant_type = "client_credentials"
scope = "https://graph.microsoft.com/.default"
client_id = $appId
client_secret = $appSecret
}
$response = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token" -Method Post -Body $body -ContentType "application/x-www-form-urlencoded"
$token = $response.access_token
Connect-MgGraph -AccessToken ($Token |ConvertTo-SecureString -AsPlainText -Force)
#disConnect-MgGraph
#(get-mgcontext).Scopes
# (get-mgcontext)
if (get-mgcontext) {write-host "Connected to O365" -ForegroundColor Green}
else { write-host "Disconnected from O365" break}
# $allMGusers = get-mguser -All # This can take time in a big environment.
# $allMGusers[222] # Lets just see what 222 looks like?
$SpecificUser.Count
Write-Host $SpecificUser.UserPrincipalName $SpecificUser.Id # Some things I am interested in
$UserDevices = Get-MgUserOwnedDevice -UserId $SpecificUser.Id
$deviceDetails = get-mgdevice -DeviceId $device.Id
write-host $deviceDetails.DisplayName';'$deviceDetails.Id';'$deviceDetails.OperatingSystemVersion';'$SpecificUser.UserPrincipalName';'$SpecificUser.Id
# Write-Host ($deviceDetails | Format-List | Out-String) # dump it all to look at it.
}