kennysarmy Posted October 9, 2024 Posted October 9, 2024 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 If that's the key that contains the correct value data. Hoping someone can help.
kennysarmy Posted October 9, 2024 Author Posted October 9, 2024 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.
kennysarmy Posted October 17, 2024 Author Posted October 17, 2024 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
dapaulio Posted October 20, 2024 Posted October 20, 2024 Can you simple not do this with group policy?
dapaulio Posted October 20, 2024 Posted October 20, 2024 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 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now