Jump to content

Recommended Posts

Posted

Hi,

 

I wonder if anyone can help.

 

I'm trying to delete a reg key found under:

 

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Enrollments\

 

I only want to delete the key (there are many) that contains a "value name" of

 

"AADResourceID"

 

with a "value data" of

 

"https://enrollment.manage.microsoft.com/"

 

eg.

I wish to delete

 

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Enrollments\C4BAAD2F-2443-469E-B9E7-73C59EEAEF60

 

 

Capture.JPG

 

If that's the key that contains the correct value data.

 

Hoping someone can help.

Posted

ChatGPT came up with this:

 

 

# Define the registry path

$registryPath = "HKLM:\SOFTWARE\Microsoft\Enrollments"

 

# Get all subkeys under the specified path

$subKeys = Get-ChildItem -Path $registryPath

 

# Define the target value data

$targetData = "https://enrollment.manage.microsoft.com/"

 

# Loop through each subkey

foreach ($subKey in $subKeys) {

# Get all values under the subkey

$values = Get-ItemProperty -Path $subKey.PSPath

 

# Loop through each value in the subkey

foreach ($value in $values.PSObject.Properties) {

# Check if the value data matches the target

if ($value.Value -eq $targetData) {

# If a match is found, delete the subkey

Remove-Item -Path $subKey.PSPath -Recurse -Force

Write-Host "Deleted subkey: $($subKey.PSChildName)"

break

}

}

}

 

 

Explanation:

The script starts by specifying the registry path where the subkeys are located.

It retrieves all subkeys under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Enrollments.

For each subkey, it checks all its values.

If any value data matches https://enrollment.manage.microsoft.com/, it deletes that subkey using Remove-Item.

Ensure that you run the script with administrative privileges, as modifying the registry requires elevated permissions.

  • 2 weeks later...
Posted
Managed to deploy the above out as a startup script (needed to amend AppLocker policies to allow) and now all our devices are starting to appear in Intune :)

 

Ahh I see now your predicament

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...