As an IT administrator, managing devices in your organization can be a daunting task. With the help of Microsoft Graph and PowerShell, you can automate device management tasks and streamline your workflow. In this article, You can explore how to use PowerShell to connect to Microsoft Graph, retrieve a list of managed devices, and sync a specific device using below script.
# Authenticatio and Authorization to Graph API with PowerShell $scopes = "DeviceManagemenetManagedDevices.ReadWrite.All" $tenantId = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx' $clientId = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx' $ClientSecret = ConvertTo-SecureString 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx' -AsPlainText -Force $clientSecretCredential = New-Object System.Management.Automation.PSCredential($clientId, $clientSecret) # Connect to MGGraph Connect-mgGraph -TenantId $tenantId -ClientSecretCredential $clientSecretCredential #-NoWelcome -Scopes $scopes # List All MDM Intune devices and count $devices = Get-MgDeviceManagementManagedDevice -All $devices[0] $devices.Count # Sync MDM Intune device with device ID Sync-MgDeviceManagementManagedDevice -ManagedDeviceId $devices[0].Id
Download this script MDM-SyncIntuneDevicesPowershell.ps1 here or it is also available on github.com.
Useful Articles
PowerShell & Microsoft Graph API: Automate Full Intune Devices Sync more than 1000 Pagination
Automate Intune MDM Device Sync: A PowerShell Script for Microsoft Graph API
PowerShell Create and Export Self-Signed RSA Certificates (PFX, CER, PEM)
How to switch to other Azure AD tenant using PowerShell and Azure CLI
Creating a new user in Azure AD using oneliner PowerShell and Azure CLI
Connect-AzureAD: One or more errors occurred. Could not load type 'System.Security.Cryptography.SHA256Cng'
Create a Azure Virtual Network with Subnet using PowerShell
Azure add create a Subnet to existing Virtual Network using PowerShell
Remove Azure Virtual Network Subnet using PowerShell
Create key vault and secrets with access policies in Microsoft Azure
Working With Azure Key Vault Using Azure PowerShell and AzureCLI
Use Key Vault secret identifier url to get the secret value using Powershell
Use a Azure VM system assigned managed identity to access Azure Key Vault
Create Azure Key Vault Certificates on Azure Portal and Powershell
Export certificates from Azure Key Vault using PowerShell
