Introduction
Each time a Cloud PC is created, a new device object will appear in Azure AD. This I no different from physical devices, but because we might recreate CloudPCs multiple times, the number of device objects in Azure AD can get out of control.
The issue
One of the core elements of Windows 365 is the Reprovisioning feature, which allows IT Administrators to recreate a user’s Cloud PC within minutes. Even though the old Cloud PC is being deleted from Intune, the device object still exists in Azure AD. Because Reprovisioning of Cloud PCs might be done quite frequently depending on how many Cloud PCs and issues the users face. The number of old device objects in Azure AD might increase quite fast.
The solution
If you already have a good flow to cleanup your stale physical devices, it will properly also work with Cloud PCs. If not, I have created a script that can handle that. I usually recommend disabling the device object and waiting some time before deleting it. But because the Cloud PC is deleted when doing a Reprovisioning, there is no need to save that device object.
Use of the script is at your own risk. I’ll highly recommend setting the parameter ‘$DeleteOldCloudPCDevices’ to $False to start with. This way, you will get an overview of which devices will be deleted.
There are three parameters to know before getting started.
$ExportToCSV: Specifying a path like C:\Temp, will out a .csv file called Delete_Old_CloudPC_Devices to that path.
$Graceperiod: Adding a higher number like ‘100’ will only delete devices older than 100 days. Specifying ‘0’ will delete all old devices, no matter how old they are.
$DeleteOldCloudPCDevices: Setting this parameter to $True will delete old devices if they are older than the days specified in the parameter $Graceperiod above. Setting it to $False will not delete old devices but will output what will be deleted if you set it to true.
Go to my Github repo to find the script, along with a description of what graph permissions and modules you will need to run the script.
Final Thoughts
Having your Azure AD nice and clean is satisfying but is also practical at the same time. Only having a few Cloud PCs might not create that many stale devices for you to care about, but imagine having thousands of Cloud PCs and you reprovisioning a couple of those every week. They will quickly add up.
Pingback: Intune Newsletter - 28th October 2022 - Andrew Taylor