Powershell Script not pulling Registry Hive info
We are trying to implement a powershell script in KACE that will delete the Intune registration from certain PCs (trying to correct an enrollment issue that happened in one of our offices). The script works fine when run manually on PCs, but running it from KACE produces multiple errors. I've been able to track down the issue to this command:
When we run that script, we are expecting to get an output similar to this stored in $locatekeyname:
Hive: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Enrollments\2A776205-D75A-405E-BC49-A60137F9CB80
Name Property
---- --------
DeviceEnroller FirstScheduleTimestamp : {229, 7, 10, 0...}
FirstSessionTimestamp : {73, 118, 105, 133...}
However, when we run it via KACE via local system, the variable is blank, which cascades into causing the rest of the script to fail. I've tried adjusting the script to look at HKLM64, tried running Powershell.exe from sysnative instead of the dependency directory, and also tried running as a specific admin user. But no matter what we try, it still fails. We could really use some help on this to figure out why the hive info is not populating into the variable. Does anyone have any ideas on how to get it to pull that data?
Answers (1)
Hi FreedanZero,
I use to face issues like that in the past but can't exactly remember what was the solution. After browsing my scripts, I can see that I always write it like that since this time :
$registryPath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Enrollments"
$registryKeys = Get-ChildItem $registryPath -recurse
So in your exemple,
$locatekeyname = Get-ChildItem -path "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Enrollments" -recurse -ErrorAction SilentlyContinue | Where-Object {$_.PSChildName -contains "DeviceEnroller"} | Out-String
Let us know,Nioky