Skip to content

Report tenant devices

directorcia edited this page Dec 9, 2024 · 4 revisions

Script = graph-devices-get.ps1

PowerShell Script: graph-devices-get.ps1

The graph-devices-get.ps1 script is designed to interact with the Microsoft Graph API to retrieve and display information about devices. Below is a step-by-step explanation of its operation and functionality:

1. Output the Devices

$devicesummary | Format-Table DisplayName, DeviceId, OperatingSystem, Trusttype

This line formats and outputs the device summary information in a table format. The table includes columns for DisplayName, DeviceId, OperatingSystem, and Trusttype.

2. Output to CSV (if specified)

if ($csv) {
    Write-Host -ForegroundColor $processmessagecolor "`nOutput to CSV: $outputFile"
    $devicesummary | Export-Csv $outputFile -NoTypeInformation
}

If the $csv variable is set (indicating that the user wants to export the data to a CSV file), the script:

  • Writes a message indicating the output file.
  • Exports the device summary to the specified CSV file using the Export-Csv cmdlet.

3. Script Completion Message

Write-Host -ForegroundColor $systemmessagecolor "`nGraph devices script - Finished"

This line outputs a message indicating that the script has finished executing.

4. Stop Transcript (if debugging)

if ($debug) {
    Stop-Transcript | Out-Null
}

If the $debug variable is set (indicating that debugging is enabled), the script stops the transcript recording using the Stop-Transcript cmdlet and discards the output using Out-Null.


Summary

  • The script retrieves device information from Microsoft Graph and stores it in the $devicesummary variable.
  • It then formats and displays the device information in a table.
  • If the user specifies to export the data to a CSV file, the script writes the data to the specified file.
  • Finally, it outputs a completion message and stops the transcript if debugging is enabled.

This script is useful for administrators to retrieve, display, and optionally export device information managed by Microsoft Graph.