Reputation: 333
i'm trying to search any value name in the registry (HKLM:\Cluster\Resources) that match = VirtualServerName. and output his associated datakey to an array.
For Example:
Name Type Data
VirtualServerName REG_SZ SQLDEP05
But i couldn't find the right switch for a recurring search with the Get-ItemProperty command.
so ive tried using the Get-ChileItem insted:
$Reg = "HKLM:\Cluster\Resources\"
Get-ChildItem -recurse "$Reg" | Select-Object -Property VirtualServerName -ExcludeProperty $exclude | ForEach-Object { $_.PSObject.Properties.Value }
Which works only when im using the .Name option in the $_.PSObject.Properties switch.
But when i'm trying to get the value of VirtualServerName, .Value:
$Reg = "HKLM:\Cluster\Resources\"
Get-ChildItem -recurse "$Reg" | Select-Object -Property VirtualServerName -ExcludeProperty $exclude | ForEach-Object { $_.PSObject.Properties.Value }
i don't get any output.
Upvotes: 1
Views: 452
Reputation: 174435
Use Where-Object
to test if a value name exists under a specific key with the GetValueNames()
method:
$Keys = Get-ChildItem -Path $Reg -Recurse |Where-Object {$_.GetValueNames() -contains 'VirtualServerName'}
Now that you've got the relevant key(s), you can grab the value data with Get-ItemProperty
:
$Keys |Get-ItemProperty VirtualServerName
or the GetValue()
method:
$Keys |ForEach-Object {
$_.GetValue('VirtualServerName')
}
Upvotes: 2