From 61c07414b16b705e49585c60997f563cb138b18e Mon Sep 17 00:00:00 2001 From: Gupta Date: Sat, 20 Dec 2025 23:34:41 +0100 Subject: [PATCH 1/3] =?UTF-8?q?t:=20add=20AVD=20device=20filtering=20with?= =?UTF-8?q?=20optional=20name=E2=80=91based=20override?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit introduces the new -AVDDevices switch and optional -AVDUniqueIdentifier parameter. When enabled, the script filters Intune devices using either a custom device name identifier or the default model = "Virtual Machine" logic. This allows exporting both AVD single-session and multi-session devices while keeping the default behavior unchanged. --- Export-IntuneManagedDevices.ps1 | 26 ++++++++++++++++++++++++++ README.md | 22 +++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/Export-IntuneManagedDevices.ps1 b/Export-IntuneManagedDevices.ps1 index aa33700..70a977b 100644 --- a/Export-IntuneManagedDevices.ps1 +++ b/Export-IntuneManagedDevices.ps1 @@ -51,6 +51,12 @@ param ( [Parameter(ParameterSetName = 'Interactive', Mandatory = $true)] [switch]$UseInteractiveLogin, + [Parameter()] + [switch]$AVDDevices, + + [Parameter()] + [string]$AVDUniqueIdentifier + [string]$LogPath = "$PSScriptRoot\IntuneManagedDevices.log", [string]$OutputDirectory = $PSScriptRoot ) @@ -139,6 +145,26 @@ function Get-IntuneDevices { # Retrieve all managed devices from Microsoft Intune $Devices = Get-MgDeviceManagementManagedDevice -All Write-Log -Message "Retrieved $($Devices.Count) devices from Microsoft Intune." + + # Apply AVD multi-session filter if requested + if ($AVDDevices) { + Write-Log -Message "Filtering for AVD multi/single session devices..." + + if ($AVDUniqueIdentifier) { + Write-Log -Message "Using device name identifier '$AVDUniqueIdentifier' for filtering." + $Devices = $Devices | Where-Object { + $_.deviceName -like "*$AVDUniqueIdentifier*" + } + } + else { + Write-Log -Message "Using default filter: model = 'Virtual Machine'" + $Devices = $Devices | Where-Object { + $_.model -eq "Virtual Machine" + } + } + Write-Log -Message "Filtered device count: $($Devices.Count)" + } + # Filter out any devices without a device name return $Devices } diff --git a/README.md b/README.md index 3ec04ef..df9b385 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ This script connects to Microsoft Intune using the Microsoft Graph API to retrie - Retrieves detailed information about managed devices in your Intune environment. - Exports device data to **JSON** and **CSV** formats for further processing and analysis. - Includes logging for transparency and troubleshooting. +- Optional AVD-specific filtering using `-AVDDevices` and `-AVDUniqueIdentifier` parameters. ## Requirements - **Microsoft Graph SDK Installation**: Install the Microsoft Graph SDK by using the following command: @@ -49,6 +50,13 @@ This script connects to Microsoft Intune using the Microsoft Graph API to retrie - `-UseInteractiveLogin`: Use this switch for interactive user login instead of client credentials. - `-LogPath`: The file path where logs should be written. Default is `IntuneDeviceSync.log` in the script's root directory. - `-OutputDirectory`: Directory where output files (JSON and CSV) will be saved. Default is the script's root directory. +- `-AVDDevices` : Enables filtering for Azure Virtual Desktop devices (both single‑session and multi‑session). + - When enabled, the script filters devices using one of the methods: + - **Default :** model="Virtual Machine"
+ Captures all Azure-based VMs entolled in Intune. They are very likely to be AVD devices. + - **Override :** device name identifier
+ If `-AVDUniqueIdentifier` is provided, the script filters devices whose names contain the specified string. + - `AVDUniqueIdentifier` : Optional string used to filter AVD devices by name pattern (e.g., `"AVD"`, `"POOL"`, `"SESSION"`). ## Usage @@ -64,9 +72,21 @@ This command will use the specified Client ID, Tenant ID, and Client Secret to a ``` This command will prompt you to log in interactively using your user credentials. +### Example 3: Export Only AVD Devices (Default Model Filter) +```powershell +.\Export-IntuneManagedDevices.ps1 -UseInteractiveLogin -AVDDevices +``` + +### Example 4: Export Only AVD Devices Using Name Identifier +```powershell +.\Export-IntuneManagedDevices.ps1 -UseInteractiveLogin -AVDDevices -AVDUniqueIdentifier "AVD" +``` + ## Script Details - **Logging**: The script logs all activities, including authentication attempts, data retrieval, and export status, in a log file (`IntuneDeviceSync.log`). This helps in auditing and troubleshooting issues. -- **Data Filtering**: The script filters out devices that do not have a `deviceName` property set. +- **Data Filtering** + - The script filters out devices that do not have a `deviceName` property set. + - When `-AVDDevices` is used, additional filtering is applied. - **Export**: The retrieved data is exported in two formats: - **JSON**: Contains device details such as `deviceName`, `id`, `model`, and `lastSyncDateTime`. - **CSV**: Contains similar information to the JSON output for easy viewing and processing. From da682c762d34146740f8e9f11a4f63699820e086 Mon Sep 17 00:00:00 2001 From: Gupta Date: Sat, 20 Dec 2025 23:42:30 +0100 Subject: [PATCH 2/3] docs: created CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..ea9d05a --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ +## [1.2.0] - 2025-01-20 +### Added +- Added -AVDDevices switch to filter Azure Virtual Desktop devices. +- Added -AVDUniqueIdentifier parameter to support name-based filtering. \ No newline at end of file From cce6097629c4afe0fdea712977164762a1c39e5e Mon Sep 17 00:00:00 2001 From: Handover2AI-byExistence Date: Mon, 5 Jan 2026 15:39:52 +0100 Subject: [PATCH 3/3] Fix: addressed Tim's feedback. Added , after --- Export-IntuneManagedDevices.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Export-IntuneManagedDevices.ps1 b/Export-IntuneManagedDevices.ps1 index 70a977b..c34cfef 100644 --- a/Export-IntuneManagedDevices.ps1 +++ b/Export-IntuneManagedDevices.ps1 @@ -55,7 +55,7 @@ param ( [switch]$AVDDevices, [Parameter()] - [string]$AVDUniqueIdentifier + [string]$AVDUniqueIdentifier, [string]$LogPath = "$PSScriptRoot\IntuneManagedDevices.log", [string]$OutputDirectory = $PSScriptRoot