I'm trying to get a feel for the idioms to use in PowerShell.
Given this script:
$path = 'hkcu:SoftwareMicrosoftWindowsCurrentVersionExtensions'
$key = Get-Item $path
$key
I get the output at the bottom of this question.
I'd like to get output of the properties (the name/value pairs under the $key
) where I can filter on both name and value.
For instance, filter to list all the Extensions that have:
- name like
xls*
- or value like
*MSACCESS.EXE
Or an exclude filter: exclude all names like doc*
Fir the first filter, I'd want a result like this:
Name Value
---- --------
xlsx C:PROGRA~2MICROS~1Office15EXCEL.EXE
xls C:PROGRA~2MICROS~1Office15EXCEL.EXE
mdb C:PROGRA~2MICROS~1Office15MSACCESS.EXE
mda C:PROGRA~2MICROS~1Office15MSACCESS.EXE
This is the original output of the script:
Hive: HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersion
Name Property
---- --------
Extensions rtf : C:PROGRA~2MICROS~1Office15WINWORD.EXE ^.rtf
dot : C:PROGRA~2MICROS~1Office15WINWORD.EXE ^.dot
dotm : C:PROGRA~2MICROS~1Office15WINWORD.EXE ^.dotm
dotx : C:PROGRA~2MICROS~1Office15WINWORD.EXE ^.dotx
docm : C:PROGRA~2MICROS~1Office15WINWORD.EXE ^.docm
docx : C:PROGRA~2MICROS~1Office15WINWORD.EXE ^.docx
doc : C:PROGRA~2MICROS~1Office15WINWORD.EXE ^.doc
xlsx : C:PROGRA~2MICROS~1Office15EXCEL.EXE
xls : C:PROGRA~2MICROS~1Office15EXCEL.EXE
mdb : C:PROGRA~2MICROS~1Office15MSACCESS.EXE
mda : C:PROGRA~2MICROS~1Office15MSACCESS.EXE
Edit
I solved part of the problem: getting a list of Name/Value pairs. It uses PSCustomObject:
$namevalues = $key.GetValueNames() | ForEach-Object { [pscustomobject]@{ Name=$_; Value=$key.GetValue($_) } }
$namevalues
(How should I wrap that code?)
Any help with the filtering would be much appreciated
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…