Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Problem when working with loaded registry hive

$
0
0

Hi All, 

I'm working on a project to copy some registry entries to the HKLM hive so they can be inventoried using SCCM. I've spent quite a bit of time trying to figure out the best way to do this, since the keys only exist in the HKCU branch of the registry.

Here is what I've got so far:

if (Test-Path -Path C:\Users\User.dom)
{
reg load 'HKLM\TempUser' C:\Users\User.dom\ntuser.dat  

if (Test-Path -literalPath "HKLM:\TempUser\Software\Smith Micro\VZAM - Verizon Wireless\DeviceMDN")
{$Key = (get-item -literalpath "HKLM:\TempUser\Software\Smith Micro\VZAM - Verizon Wireless\DeviceMDN")
 $MEID = (Get-Item -path $Key).property
 $Number = (Get-ItemProperty -path $key -name $MEID).$meid
}

write-host "MEID is $MEID" 
Write-Host "Number is $number"


[gc]::collect()

reg unload 'hklm\TEMPuser'

new-item -path "HKLM:\Software\" -name "Inventory"
New-ItemProperty -Path "HKLM:\Software\Inventory" -Name "MEID" -value $meid -PropertyType "String" -force
New-ItemProperty -Path "HKLM:\Software\Inventory" -Name "Phone Number" -value $number -PropertyType "String" -force

}
The problem is that it works fine if I don't use the $key variable and manually enter the path on each line. Once I try to use the $key variable I get an error message that the path doesn't exist. Can't seem to figure out why that is happening.


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>