Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays Powershell-将Itemproperty获取到数组中_Arrays_Powershell - Fatal编程技术网

Arrays Powershell-将Itemproperty获取到数组中

Arrays Powershell-将Itemproperty获取到数组中,arrays,powershell,Arrays,Powershell,我正在编写powershell脚本以查找所有组件注册表项,这些注册表项下有一个数据项“00004109F100C0400000000000F01FEC”。下面的powershell返回我想要的结果,但是我希望“$test”是一个数组,这样我就可以遍历每个值。在下面的代码中,它不是,我不知道为什么 $test = @() $test = Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\

我正在编写powershell脚本以查找所有组件注册表项,这些注册表项下有一个数据项“00004109F100C0400000000000F01FEC”。下面的powershell返回我想要的结果,但是我希望“$test”是一个数组,这样我就可以遍历每个值。在下面的代码中,它不是,我不知道为什么

$test = @()
$test = Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\ | ForEach-Object { (Get-ItemProperty $_.pspath -Name "00004109F100C0400000000000F01FEC" -ErrorAction SilentlyContinue).PSPath }

如何修改上述内容,使$test中的结果成为我可以循环使用的组件键数组?

看看这是否更有效:

$test = Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Components\ |
 Where { $_.Property -eq "00004109F100C0400000000000F01FEC" } |
 select -ExpandProperty PSPath

太好了,非常感谢。这正是我想做的@mjolinor-当
%pspath
输出相同的内容时,为什么要使用
select-expandproperty pspath
?@keithHill-主要是出于性能考虑而养成的习惯。select比foreach快,不过在这种情况下,差异可能太小,不必担心。@mjolinor好吧,性能更快,输入速度更快。对于性能,最快的可能是
(Get ChildItem…| Where…。PSPath
。但是,是的,我肯定我的习惯也很好——不是所有的都好。:-)我知道。INHO,最糟糕的是当tab完成成为肌肉记忆时,你开始尝试在Powershell之外完成它。