Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate Autopilot profiles deletions result in errors #51

Open
rick-engle opened this issue Dec 16, 2024 · 3 comments
Open

Duplicate Autopilot profiles deletions result in errors #51

rick-engle opened this issue Dec 16, 2024 · 3 comments

Comments

@rick-engle
Copy link

This bulk delete tool is simply fantastic! I did find one scenario where it is failing to delete types of Intune objects which is for Autopilot profiles.
Shown below is an example of duplicate Autopilot profiles:
image

When I select some of the duplicates and proceed, they are not deleted, and I get these error messages:
Installing Microsoft Graph modules if required (current user scope)
Microsoft Graph Already Installed
Version 2 module detected
Connected to Intune tenant
20dd3f34-d210-423d-93c5-fa0412b41b05
It's an Autopilot Profile
Invoke-MgGraphRequest : DELETE
https://graph.microsoft.com/beta/deviceManagement/windowsAutopilotDeploymentProfiles/20dd3f34-d210-423d-93c5-fa0412b41b05
HTTP/1.1 400 Bad Request
Transfer-Encoding: chunked
Vary: Accept-Encoding
Strict-Transport-Security: max-age=31536000
request-id: 4b058a4d-a784-41c7-95ed-b83996791a7e
client-request-id: cb37c5a5-2535-49f4-9c79-1668688b25c2
x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"West Central US","Slice":"E","Ring":"2","ScaleUnit":"000","RoleInstance":"CY4PEPF00013268"}}
Date: Mon, 16 Dec 2024 15:27:43 GMT
Content-Encoding: gzip
Content-Type: application/json
{"error":{"code":"BadRequest","message":"{\r\n "_version": 3,\r\n "Message": "An error has occurred - Operation ID (for customer support):
00000000-0000-0000-0000-000000000000 - Activity ID: cb37c5a5-2535-49f4-9c79-1668688b25c2 - Url: https://fef.amsua0102.manage.microsoft.com/DeviceEn
rollmentFE/StatelessDeviceEnrollmentFEService/deviceManagement/windowsAutopilotDeploymentProfiles('20dd3f34-d210-423d-93c5-fa0412b41b05')?api-versi
on=5023-06-28",\r\n "CustomApiErrorPhrase": "",\r\n "RetryAfter": null,\r\n "ErrorSourceService": "",\r\n "HttpHeaders": "{}"\r
n}","innerError":{"date":"2024-12-16T15:27:43","request-id":"4b058a4d-a784-41c7-95ed-b83996791a7e","client-request-id":"cb37c5a5-2535-49f4-9c79-166
8688b25c2"}}}
At C:\Users\ricke\Documents\files\My Documents\Security and Compliance\Azure AD\scripts\Bulk delete Intune configs.ps1:1339 char:16

  •            Invoke-MgGraphRequest -uri $uri -method Delete
    
  •            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (Method: DELETE,...nt-Length: 0
      }:HttpRequestMessage) [Invoke-MgGraphRequest], HttpResponseException
    • FullyQualifiedErrorId : InvokeGraphHttpResponseException,Microsoft.Graph.PowerShell.Authentication.Cmdlets.InvokeMgGraphRequest
      Deleted

ClientId : 14d82eec-204b-4c2f-b7e8-296a70dab67e
TenantId : c39ecc73-1d29-4b61-a7c4-9f72eac49e60
Scopes : {AdministrativeUnit.Read.All, AdministrativeUnit.ReadWrite.All, Agreement.Read.All, Application.Read.All...}
AuthType : Delegated
TokenCredentialType : InteractiveBrowser
CertificateThumbprint :
CertificateSubjectName :
SendCertificateChain : False
Account : [email protected]
AppName : Microsoft Graph Command Line Tools
ContextScope : CurrentUser
Certificate :
PSHostVersion : 5.1.26100.2161
ManagedIdentityId :
ClientSecret :
Environment : Global

Would you have any idea why these particular profiles cannot be successfully deleted?

Thank you,
Rick

@andrew-s-taylor
Copy link
Owner

Hi Rick,
Check if the profiles are assigned, Autopilot profiles won't delete if they have assignments (even in the UI). It's caught me out a few times :)

@rick-engle
Copy link
Author

@andrew-s-taylor You were right! I have been using a tool to migrate Intune policies from one Azure tenant to another and it had a bug which has been creating extensive duplicates of some policies and profiles like this Autopilot profile which unfortunately has an assignment to it. So, I guess I need to manually remove all of the assignments then I could use your poulk tool to remove those dupes. Thank you.

@andrew-s-taylor
Copy link
Owner

You could see if mine works any better:
https://github.com/andrew-s-taylor/public/blob/main/Powershell%20Scripts/Intune/intune-backup-restore-withgui.ps1

Yes, you'll need to unassign these and then delete them.

Good luck :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants