从注册表项中提取条目列表并检查它们是否包含在数组中
Pulling a list of entries from Registry key and checking them for anything that is contained in an array
我正在使用以下代码尝试拉出系统上已安装软件的列表,并检查列表中的某些条目,到目前为止,我已经设法根据需要将软件列表添加到 运行使用以下代码:
$path = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
Get-ChildItem $path | Get-ItemProperty | Select-Object DisplayName
if (ItemProperty -Name -eq ('Wacom Tablet')) {
start notepad.exe
}
我希望这是一个引用 DisplayName
列表的数组,但出现以下错误:
ItemProperty : Cannot find path 'C:\WINDOWS\system32\Wacom Tablet' because it
does not exist.
At C:\Users\username\Documents\Scripts\win10test.ps1:39 char:5
+ if (ItemProperty -Name -eq ('Wacom Tablet')) {
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\WINDOWS\system32\Wacom Tablet:String) [Get-ItemProperty], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemPropertyCommand
我怎样才能做到这一点?
ItemProperty
扩展为 Get-ItemProperty
,因此您的 if
条件
ItemProperty -Name -eq ('Wacom Tablet')
变成
Get-ItemProperty -Name -eq -Path ('Wacom Tablet')
意味着您的代码正在尝试从当前工作目录中的项目 Wacom Tablet
获取 属性 -eq
(在您的情况下显然是 C:\WINDOWS\system32
)。
您似乎想做的是这样的事情:
Get-ChildItem $path | Get-ItemProperty |
Where-Object { $_.DisplayName -eq 'Wacom Tablet'} |
ForEach-Object {
# do stuff
}
或者像这样:
$prop = Get-ChildItem $path | Get-ItemProperty |
Select-Object -Expand DisplayName
if ($prop -eq 'Wacom Tablet') {
# do stuff
}
我正在使用以下代码尝试拉出系统上已安装软件的列表,并检查列表中的某些条目,到目前为止,我已经设法根据需要将软件列表添加到 运行使用以下代码:
$path = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
Get-ChildItem $path | Get-ItemProperty | Select-Object DisplayName
if (ItemProperty -Name -eq ('Wacom Tablet')) {
start notepad.exe
}
我希望这是一个引用 DisplayName
列表的数组,但出现以下错误:
ItemProperty : Cannot find path 'C:\WINDOWS\system32\Wacom Tablet' because it does not exist. At C:\Users\username\Documents\Scripts\win10test.ps1:39 char:5 + if (ItemProperty -Name -eq ('Wacom Tablet')) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\WINDOWS\system32\Wacom Tablet:String) [Get-ItemProperty], ItemNotFoundException + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemPropertyCommand
我怎样才能做到这一点?
ItemProperty
扩展为 Get-ItemProperty
,因此您的 if
条件
ItemProperty -Name -eq ('Wacom Tablet')
变成
Get-ItemProperty -Name -eq -Path ('Wacom Tablet')
意味着您的代码正在尝试从当前工作目录中的项目 Wacom Tablet
获取 属性 -eq
(在您的情况下显然是 C:\WINDOWS\system32
)。
您似乎想做的是这样的事情:
Get-ChildItem $path | Get-ItemProperty |
Where-Object { $_.DisplayName -eq 'Wacom Tablet'} |
ForEach-Object {
# do stuff
}
或者像这样:
$prop = Get-ChildItem $path | Get-ItemProperty |
Select-Object -Expand DisplayName
if ($prop -eq 'Wacom Tablet') {
# do stuff
}