9

Deletes device records in AD / AAD / Intune / Autopilot / ConfigMgr for Autopilo...

 1 year ago
source link: https://gist.github.com/SMSAgentSoftware/27ff318f3973b97ca6b5cb99e8c93293
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

ConfigMgr for Autopilot Test Deployments · GitHub

Instantly share code, notes, and snippets.

Deletes device records in AD / AAD / Intune / Autopilot / ConfigMgr for Autopilot Test Deployments

The specified module 'AzureAD' was not loaded because no valid module file was found in any module directory. Please advise.

The specified module 'AzureAD' was not loaded because no valid module file was found in any module directory. Please advise.

It happened to me too with "-All". I think it is the ConfigMgr option. When I just use "-AAD -Intune -Autopilot" it works fine.

Very cool. To make it work for my environment, I changed the order of the deletion process and added a 2 minute Sleep after Autopilot delete to give the service enough time. Autopilot should never be deleted before Azure.

If I enter a computer name 'Brown' it will delete Brown Brown1 Brown2. Is there a code change I can make so it only deletes exact matches?

I run this script with -Autopilot -AAD -Intune, using a CSV as per the below.

I get a success for all removals, but when I check AutoPilot, all of the devices are still listed?

$computer_list = Import-Csv "c:\Scripts\TestComputerName.csv"
foreach ($computer in $computer_list)
{
.\Delete-AutopilotedDeviceRecords.ps1 -ComputerName $($computer.ComputerName) -Autopilot -AAD -Intune
}

If I enter a computer name 'Brown' it will delete Brown Brown1 Brown2. Is there a code change I can make so it only deletes exact matches?

That happened to me too! Luckily it was only pilot devices.
.\Delete-AutopilotedDeviceRecords.ps1 -ComputerName LAB -Intune -AAD

Thanks Trevor - Love your work on this.
To be unique, I changed the search to "Get-AzureADDevice -All:$True -ErrorAction Stop | Where { .DisplayName−eq($ComputerName) } }"
as it didn't like the -Filter switch inside ps1 (given literal string i believe).

The specified module 'AzureAD' was not loaded because no valid module file was found in any module directory. Please advise.

You need to install the module first. Inject these at the begining of your script.

Install-Module Microsoft.Graph.Intune -ErrorAction Stop -Force -Confirm:$false -Verbose
Install-Module AzureAD -ErrorAction Stop -Force -Confirm:$false -Verbose

Desiqnx3 commented on Jun 14

edited

Hi all!
I have the problem, that one autopilot rollout failed. And now there are two devices with the exact name. One is Hybrid Joined and one Azure AD joined(in activ since 2021), both autopilot devices. Is there an way, how can i remove only that "Azure AD joined" device? I have the fear that I delete both with the command. (even if I use e.g. only azure ad, because there they are both seen under the same name) Object IDs etc. are different.

You don't need to, once policy syncs in, the wrong object will vanish. If still required, us PS to find the corresponding object ID and deleted the wrong one. Thanks and Regards Raghu Sharma

This worked for me. But the device was still in MSfB, I had to delete it from there then re-import csv.

When I run this script, all it does is asks for the computer to delete, it doesn't prompt to connect to AAD or anything else

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK