无法通过Powershell从Regedit提取信息

时间:2014-07-07 09:20:11

标签: powershell

我无法使用此代码:

  

Get-ChildItem hklm:\ software \ microsoft \ windows \ currentversion \ uninstall | ForEach- Object {Get-ItemProperty $ .pspath} |   Where-Object {$ .DisplayName -Eq' Microsoft Lync 2013'} |选择对象DisplayVersion

我做错了什么?

这个工作正常,它们都在注册表中,我知道这个例子不是en wow6432node,这可能是问题吗?

  

Get-ChildItem hklm:\ software \ microsoft \ windows \ currentversion \ uninstall | ForEach-Object {Get-ItemProperty $ .pspath} |   Where-Object {$ .DisplayName -Eq' Microsoft Security Client'} |选择对象DisplayVersion

1 个答案:

答案 0 :(得分:-1)

您有几个语法错误。在这种情况下,我尝试将单行分解为多个步骤并编写.ps1文件以发现错误。将其复制到您选择的文件中:

$a = Get-ChildItem hklm:\software\microsoft\windows\currentversion\uninstall 
$b = $a | ForEach-Object {  Get-ItemProperty $_.pspath} 
$c = $b | Where-Object { $_.DisplayName -Eq 'Microsoft Lync 2013'} 
$d = $c | Select-Object DisplayVersion

write-host `$d.length  $d.length
write-host content of `$d 
$d

write-host 
write-host intermediate results were:
write-host `$c.length  $c.length
write-host `$b.length  $b.length
write-host `$a.length  $a.length  

pause

在我的情况下,在步骤$ c之后我没有得到任何结果,因为我没有安装Microsoft Lync 2013:

PS> .\test.ps1
$d.length 0
content of $d

intermediate results were:
$c.length 0
$b.length 976
$a.length 992
Drücken Sie die Eingabetaste, um den Vorgang fortzusetzen...: