powershell - Pulling a list of entries from Registry key and checking them for anything that is contained in an array -
i using following code try , pull list of installed software on system , check entries within list, far have managed software list run desired using following code:
$path = 'hklm:\software\microsoft\windows\currentversion\uninstall\*' get-childitem $path | get-itemproperty | select-object displayname if (itemproperty -name -eq ('wacom tablet')) { start notepad.exe }
i array references displayname
list, following error:
itemproperty : cannot find path 'c:\windows\system32\wacom tablet' because not exist. @ 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
how achieve this?
itemproperty
expanded get-itemproperty
, if
condition
itemproperty -name -eq ('wacom tablet')
becomes
get-itemproperty -name -eq -path ('wacom tablet')
meaning code trying property -eq
item wacom tablet
in current working directory (in case apparently c:\windows\system32
).
what seem want this:
get-childitem $path | get-itemproperty | where-object { $_.displayname -eq 'wacom tablet'} | foreach-object { # stuff }
or this:
$prop = get-childitem $path | get-itemproperty | select-object -expand displayname if ($prop -eq 'wacom tablet') { # stuff }
Comments
Post a Comment