Advertisement
Wasif_Hasan_

Get-KeyProperty (Powershell function)

Aug 14th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Get-KeyProperty
  2. # Actually this is a powershell function
  3. # While you explore a registry key using Powershell Get-ItemProperty CMDLet, There are annoying PS* properties
  4. # Then you can add this function to your $PROFILE and now use this CMDLet instead of Get-ItemProperty
  5. # PS* properties will be removed
  6. # Usage:  Get-KeyProperty "Registry Key path"
  7.  
  8. Function Get-KeyProperty {
  9.   [CmdletBinding()]
  10.   Param(
  11.     [Parameter(Mandatory=$True)]
  12.     [ValidateScript({Test-Path $_})]
  13.     [String]$RegPath
  14.   )
  15.   $Values = New-Object PSObject
  16.   Get-ItemProperty "$RegPath" |
  17.     Get-Member -MemberType NoteProperty |
  18.       Where-Object {$_.Name -notlike "PS*"} | Foreach {
  19.         $_ | Select-Object -ExpandProperty Name | Foreach {
  20.           $Value = Get-ItemProperty "$RegPath" -Name "$_"
  21.           $Values |
  22.             Add-Member -MemberType NoteProperty -Name "$_" -Value "$($Value."$_")"
  23.         }
  24.       }
  25.    Return $Values
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement