Apr 21 2022 12:06 AM - edited Apr 21 2022 12:11 AM
I am looking for a script to fully remove an (Autopilot) device from a Microsoft tenant. The goal is to remove a specific device that I have physical access to from both Microsoft Endpoint Manager (Intune) and Azure AD. I want to accomplish this by running a (PowerShell) script on the device itself. The script should return output to indicate success or failure.
Please keep the following parameters in mind: Before running the script, I have access to the physical device and I know the serial number of the device. I do not know the deviceID or tenant of the specific device, but I do have an Intune Admin account in the tenant where the device sits. The device is an Autopilot device. I do not want to log into the Microsoft tenant directly but only run scripts from the device itself.
Thank you very much, looking forward to any tips this community has to offer!
Apr 25 2022 12:53 AM
Solution
There's a module for autopilot things here (https://www.powershellgallery.com/packages/WindowsAutoPilotIntune/5.0),
After installing (Install-Module -Name WindowsAutoPilotIntune.), you could use this to remove the device from the Autopilot devices :
Connect-MSGraph
Get-AutoPilotDevice | Where-Object SerialNumber -eq (Get-WmiObject -class Win32_Bios).SerialNumber | Remove-AutopilotDevice
This deletes the device based on the serialnumber of the machine that you're logged into, this could take a few minutes to process in the background.
For the removal of the Azure AD device, you can use this:
Connect-Azuread
Get-AzureADDevice | Where-Object DisplayName -Match $env:COMPUTERNAME | Remove-AzureADDevice
Apr 29 2022 02:43 AM - edited May 01 2022 03:28 AM
Did this work out for you ?
May 03 2022 04:55 AM
May 03 2022 05:02 AM
May 14 2022 03:18 AM
May 16 2022 02:01 AM
May 16 2022 02:11 AM
@AEchtermeijer No problem, sometimes short scripts can be effective and easy to read too ;) Not sure if you can show the tenant name, it's a Modern Auth prompt.. But you do see the company branding, there's no info in the username hint field or sign-in page text?
And I don't think that there's a possibility that these two are different, if the computername is changed on the computer itself, it updates the Azure AD registration AFAIK