0% found this document useful (0 votes)
3 views2 pages

Script

The document provides a PowerShell script for connecting to Microsoft Graph and retrieving BitLocker recovery keys for specified devices in Azure Entra ID. It prompts the user to input device names, checks for their existence, and displays the associated recovery keys if found. If no keys are available or the device is not found, appropriate messages are displayed to the user.

Uploaded by

bluehkbb
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Script

The document provides a PowerShell script for connecting to Microsoft Graph and retrieving BitLocker recovery keys for specified devices in Azure Entra ID. It prompts the user to input device names, checks for their existence, and displays the associated recovery keys if found. If no keys are available or the device is not found, appropriate messages are displayed to the user.

Uploaded by

bluehkbb
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

# Install-Module -Name Microsoft.

Graph -Scope CurrentUser -Force

Import-Module [Link]

Import-Module [Link]

# Connect to Microsoft Graph interactively (device administrator role


required)

Connect-MgGraph -Scopes "[Link]","[Link]"

# Ask for device names (machine NAME, case-insensitive, unique within


tenant)

$deviceInput = Read-Host "Enter device names (comma, space, or line


separated)"

$deviceNames = $deviceInput -split "[,`n`r\s]+" | ForEach-Object


{ $_.Trim() } | Where-Object { $_ }

foreach ($device in $deviceNames) {

# Find device object in Azure Entra ID

$deviceObject = Get-MgDevice -Filter "displayName eq '$device'" -


Property Id,DisplayName

if ($deviceObject) {

foreach ($dev in $deviceObject) {

Write-Host "Device Found: $($[Link]) ($($[Link]))" -


ForegroundColor Cyan

$keys = Get-MgInformationProtectionBitlockerRecoveryKey -DeviceId


$[Link]

if ($keys) {

foreach ($key in $keys) {


Write-Host "Recovery Key for Device $($[Link]): $
($[Link])" -ForegroundColor Green

} else {

Write-Host "No BitLocker recovery keys found for $


($[Link])." -ForegroundColor Yellow

} else {

Write-Host "Device '$device' not found in Azure Entra ID." -


ForegroundColor Red

You might also like