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.
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.