8,330 questions
Probably because the properties are not evaluated until after the invoke-command has completed and the PSPath of the object points to a "local" name.
cls
"This demonstrates the 'Problem'"
Invoke-Command -ComputerName test10b -ScriptBlock {
"This portion of the script is running on {0}" -f $env:COMPUTERNAME
"Here is reg.exe"
reg.exe query HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName /s
"Here is the computername from the registry"
Get-ChildItem 'HKLM:\System\CurrentControlSet\Control\ComputerName'
}
cls
"This shows one way to enumerate the properties and values."
Invoke-Command -ComputerName test10b -ScriptBlock {
"This portion of the script is running on {0}" -f $env:COMPUTERNAME
"Here is reg.exe"
reg.exe query HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\ComputerName /s
"Here is Get-Childitem"
$Keys = Get-ChildItem HKLM:\System\CurrentControlSet\Control\ComputerName
foreach ($k in $keys){
$k.Name
$props = (Get-Item -Path $k.pspath).property
foreach ($p in $props) {
$v = Get-ItemPropertyvalue -Path $k.pspath -name $p
" {0} - {1}" -f $p , $v
}
}
}
To read the DotNet values I had to add -recurse.
cls
"DotNet reg key with multiple subkeys"
Invoke-Command -ComputerName test10b -ScriptBlock {
"This portion of the script is running on {0}" -f $env:COMPUTERNAME
"Here is reg.exe"
reg.exe query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4" /s
"Here is Get-Childitem"
$Keys = Get-ChildItem -recurse "HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4"
foreach ($k in $keys){
$k.Name
$props = (Get-Item -Path $k.pspath).property
foreach ($p in $props) {
$v = Get-ItemPropertyvalue -Path $k.pspath -name $p
" {0} - {1}" -f $p , $v
}
}
}