Forum Discussion
Get List of Apps from single devices (Powershell)
The script connects to Microsoft Graph, retrieves the apps assigned to a specific device, and exports the data into a CSV file if you want to export to CSV otherwise you can delet this step:
# Import the Microsoft Graph PowerShell module
Import-Module Microsoft.Graph
# Connect to Microsoft Graph with the necessary permissions
# Make sure the app has permissions: DeviceManagementApps.Read.All and DeviceManagementManagedDevices.Read.All
Connect-MgGraph -Scopes "DeviceManagementApps.Read.All", "DeviceManagementManagedDevices.Read.All"
# Define the device name for which we want to fetch the app list
$deviceName = "Device_Name" # Replace with the actual device name
# Step 1: Get the device ID by searching for the device in Intune
Write-Host "Fetching device information..."
$device = Get-MgDeviceManagementManagedDevice -Filter "displayName eq '$deviceName'"
# Check if the device exists
if ($null -eq $device) {
Write-Host "Device not found. Please verify the device name and try again." -ForegroundColor Red
return
}
$deviceId = $device.Id
Write-Host "Device ID fetched: $deviceId"
# Step 2: Retrieve the list of all apps managed by Intune
Write-Host "Fetching app assignments for the device..."
$allApps = Get-MgDeviceAppManagementMobileApps
# Step 3: Filter apps that are assigned to the specific device
$assignedApps = foreach ($app in $allApps) {
# Check if the app assignments contain the device ID
foreach ($assignment in $app.Assignments) {
if ($assignment.Target.DeviceGroupId -eq $deviceId) {
# Add app details to the output if assigned to the device
[PSCustomObject]@{
DisplayName = $app.DisplayName
Publisher = $app.Publisher
Version = $app.Version
}
}
}
}
# Step 4: Check if any apps were found
if ($assignedApps.Count -eq 0) {
Write-Host "No apps found for the specified device." -ForegroundColor Yellow
return
}
# Step 5: Export the app list to a CSV file
$outputFile = "DeviceApps_$deviceName.csv"
Write-Host "Exporting app list to $outputFile..."
$assignedApps | Export-Csv -Path $outputFile -NoTypeInformation -Encoding UTF8
Write-Host "App list exported successfully to $outputFile" -ForegroundColor Green
Let me know if this helps