Forums on Intune, SCCM, and Windows 11

Welcome to the forums. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your topics and posts, as well as connect with other members through your own private inbox!

SOLVED Can't read registry with powershell and sccm

  • Thread starter Thread starter pcb
  • Start date Start date
  • Replies Replies 2
  • Views Views 2K

pcb

Well-Known Member
Messages
45
Solutions
2
Reaction score
0
Points
6
For some reason, I can't get SCCM to read the registry with a simple powershell command.
Code in question:
try {
$registryKey = Get-Item -LiteralPath "HKLM:\Software\LCC\Device"
$behavior = $registryKey.GetValue("Behavior", $null)
} catch {
$behavior = $null
}
Write-Host $behavior
pause

When called with SCCM on the client machine I get this error:
Get-Item : Cannot find path 'HKLM:\SOFTWARE\LCC\Device' because it does not exist.
At C:\WINDOWS\ccmcache\n\InstallOESClient.ps1:3 char:20
+ $registryKey = Get-Item -LiteralPath "HKLM:\SOFTWARE\LCC\Device"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (HKLM:\SOFTWARE\LCC\Device:String) [Get-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand

But if run with Psexec.exe -i -s powershell.exe
PS C:\windows\ccmcache\n> powershell -ExecutionPolicy Bypass .\InstallClient.ps1
AppTesting
Press Enter to continue...:

It outputs the value as expected... what is going on here? Is there some special trick to reading the registry with powershell? I have several scripts that write to this same key and that is no problem.
 
Solution
With an application in SCCM - command = PowerShell.exe -ExecutionPolicy Bypass -Command ".\InstallOESClient.ps1"

And apparently that was the problem... I don't really know for sure, but I think somehow a special character got into the command. I looked it over several times and everything looked exactly right, but I retyped the command from scratch and now it is working.
With an application in SCCM - command = PowerShell.exe -ExecutionPolicy Bypass -Command ".\InstallOESClient.ps1"

And apparently that was the problem... I don't really know for sure, but I think somehow a special character got into the command. I looked it over several times and everything looked exactly right, but I retyped the command from scratch and now it is working.
 
Solution

Forum statistics

Threads
7,135
Messages
27,868
Members
18,159
Latest member
jordysmits
Back
Top