I'm trying to figure out which idioms to use in PowerShell.
Given this script:
$path = 'hkcu:\Software\Microsoft\Windows\CurrentVersion\Extensions' $key = Get-Item $path $key
I get a conclusion at the bottom of this question.
I would like to get the output of the properties (name / value pairs under $key ), where I can filter by name and value.
For example, a filter to display all extensions that have:
- name like
xls* - or a value similar to
*\MSACCESS.EXE
Or an exception filter: exclude all names, for example doc*
The first filter, I would like to get this result:
Name Value ---- -------- xlsx C:\PROGRA~2\MICROS~1\Office15\EXCEL.EXE xls C:\PROGRA~2\MICROS~1\Office15\EXCEL.EXE mdb C:\PROGRA~2\MICROS~1\Office15\MSACCESS.EXE mda C:\PROGRA~2\MICROS~1\Office15\MSACCESS.EXE
This is the original script output:
Hive: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion Name Property ---- -------- Extensions rtf : C:\PROGRA~2\MICROS~1\Office15\WINWORD.EXE ^.rtf dot : C:\PROGRA~2\MICROS~1\Office15\WINWORD.EXE ^.dot dotm : C:\PROGRA~2\MICROS~1\Office15\WINWORD.EXE ^.dotm dotx : C:\PROGRA~2\MICROS~1\Office15\WINWORD.EXE ^.dotx docm : C:\PROGRA~2\MICROS~1\Office15\WINWORD.EXE ^.docm docx : C:\PROGRA~2\MICROS~1\Office15\WINWORD.EXE ^.docx doc : C:\PROGRA~2\MICROS~1\Office15\WINWORD.EXE ^.doc xlsx : C:\PROGRA~2\MICROS~1\Office15\EXCEL.EXE xls : C:\PROGRA~2\MICROS~1\Office15\EXCEL.EXE mdb : C:\PROGRA~2\MICROS~1\Office15\MSACCESS.EXE mda : C:\PROGRA~2\MICROS~1\Office15\MSACCESS.EXE
Edit
I solved a part of the problem: get a list of Name / Value pairs. It uses PSCustomObject :
$namevalues = $key.GetValueNames() | ForEach-Object { [pscustomobject]@{ Name=$_; Value=$key.GetValue($_) } } $namevalues
(How do I wrap this code?)
Any help with filtering would be much appreciated
source share