Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Get-HashedProperty
- # This is actually a function
- # It will save the properties and values of a registry key in key-value pair and return in Hashtable/JSON
- # It will also exclude PS* Properties
- # You can add this into your $PROFILE
- # Usage: Get-HashedProperty "Registry Path" -As "JSON/Hashtable"
- # -As switch is optional, default value is Hashtable
- Function Get-HashedProperty {
- [CmdletBinding()]
- Param(
- [Parameter(Mandatory=$True)]
- [ValidateScript({Test-Path $_})]
- [String]$RegPath,
- [Parameter(Mandatory=$False)]
- [ValidateSet("Json","HashTable")]
- [String]$As
- )
- $Hash = @{}
- Get-ItemProperty "$RegPath" |
- Get-Member -MemberType NoteProperty |
- Where-Object {$_.Name -notlike "PS*"} | Foreach {
- $_ | Select-Object -ExpandProperty Name | Foreach {
- $Value = Get-ItemProperty "$RegPath" -Name "$_"
- $Hash.Add("$_","$($Value."$_")")
- }
- }
- If($As -eq "Json"){
- $Hash = $Hash | ConvertTo-Json
- }
- Return $Hash
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement