The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,089 other followers

how to filter name/value pairs under a registry key by name and value in PowerShell?

Posted by jpluimers on 2019/09/03

A very concise way for [WayBackhow to filter name/value pairs under a registry key by name and value in PowerShell?:

$path = 'hkcu:\Software\Microsoft\Windows\CurrentVersion\Extensions'
(Get-ItemProperty $path).PSObject.Properties |
  Where-Object { $_.Name -match '^xls' ` -or $_.Value -match 'msaccess.exe$' } |
  Select-Object Name, Value

Thanks montonero for getting me on that path and pointing me to the hidden PSObject property which by itself has Properties, and making me find these links with background information:

More in-depth information:

  • [WayBack] Get-Member (Microsoft.PowerShell.Utility)
    • The Get-Member cmdlet gets the members, the properties and methods, of objects. To specify the object, use the InputObject parameter or pipe an object to Get-Member. To get information about static members, the members of the class, not of the instance, use the Static parameter. To get only certain types of members, such as NoteProperties, use the MemberType parameter.
    • -Force

      Adds the intrinsic members (PSBase, PSAdapted, PSObject, PSTypeNames) and the compiler-generated get_ and set_ methods to the display. By default, Get-Member gets these properties in all views other than Base and Adapted, but it does not display them.

      The following list describes the properties that are added when you use the Force parameter:

      • PSBase: The original properties of the .NET Framework object without extension or adaptation. These are the properties defined for the object class and listed in MSDN.
      • PSAdapted. The properties and methods defined in the Windows PowerShell extended type system.
      • PSExtended. The properties and methods that were added in the Types.ps1xml files or by using the Add-Member cmdlet.
      • PSObject. The adapter that converts the base object to a Windows PowerShell PSObject object.
      • PSTypeNames. A list of object types that describe the object, in order of specificity. When formatting the object, Windows PowerShell searches for the types in the Format.ps1xml files in the Windows PowerShell installation directory ($pshome). It uses the formatting definition for the first type that it finds.
  • [WayBack] PSObject Class (System.Management.Automation)
    • Wraps an object providing alternate views of the available members and ways to extend them. Members can be methods, properties, parameterized properties, etc.
  • [WayBack] PSObject.Properties Property (System.Management.Automation)
    • Gets the Property collection, or the members that are actually properties.
      Is of type PSMemberInfoCollection<PSPropertyInfo>
  • [WayBack] PSMemberInfoCollection<T> Class
    • Serves as the collection of members in an PSObject or MemberSet
  • [WayBack] PSPropertyInfo Class (System.Management.Automation)
    • Serves as a base class for all members that behave like properties.
  • [WayBack] Difference between PSObject, Hashtable and PSCustomObject
  • [WayBack] Combining Objects Efficiently – Use a Hash Table to Index a Collection of Objects
    • With objects objects everywhere it may not seem apparent, but hash tables are still needed.  When the PowerShell mind sets to work it can be very easy to use where and selects everywhere to get you…
  • [Archive.isCustom objects default display in PowerShell 3.0
  • [WayBack] Using PSObject to store data in PowerShell | 9to5IT
    • PowerShell’s PSObject is a powerful tool which is used to store, retrieve, sort and export data. Here is how to use PSObject to store data in PowerShell.

–jeroen

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: