Code Monkey home page Code Monkey logo

convertfrom-registry's Introduction

Get Values (Recursively if desired) from a Registry Key and return them as a Hashtable.

Works well with REQUIREMENTS.json.

Description

This returns a hashtable of all Values and Data for a given Registry Key. If the Default Value for a Key, is set it will be returned as (default).

Parameters

Key

  • Type: [System.Management.Automation.PathInfo]

This is the Registry Key you want to look in.

This parameter expects apath via PSDrive for the Registry Hive. The best way to achieve this is with Resolve-Path; see examples.

Ignore

  • Type: [System.Collections.ArrayList]

List of Parameters and/or Sub-Keys that you wish to ignore.

Recurse

  • Type: [Switch]

Use if you want to traverse into sub-keys.

OUTPUTS

[System.Collections.Hashtable] [System.Boolean]::$false

Examples

Basic Usage

Get the Values from the supplied Key. Do not recurse.

$reg = Resolve-Path 'HKLM:\SOFTWARE\TestApp' -ErrorAction Stop
$reg = ConvertFrom-Registry $reg

One Liner, Recursive

Get the Values from the supplied Key. Recurse into sub-Keys.

$reg = ConvertFrom-Registry (Resolve-Path 'HKLM:\SOFTWARE\TestApp' -ErrorAction Stop) -Recurse

Use to Set Configurable Settings From the Registry

Set some Default Settings in a script, then overwrite with setting in the Registry; possibly supplied via GPO. Ignore Parameters and Arguments as they are reserved words and not configurable.

$TestApp = @{}
$TestApp.Server = 'testapp.its.cas.unt.edu'
$TestApp.Format = 'html'
$TestApp.Parameters = $MyInvocation.BoundParameters
$TestApp.Arguments = $MyInvocation.UnboundArguments

$Key = Resolve-Path 'HKLM:\SOFTWARE\TestApp\' -ErrorAction Stop
$TestApp_Registry = ConvertFrom-Registry -Key $Key -Recurse -Ignore @('Parameters','Arguments')
foreach ($SettingFromGPO in $TestApp_Registry.GetEnumerator()) {
    $TestApp.($SettingFromGPO.Name) = $SettingFromGPO.Value
}

Note: This example is the reason I wrote this function.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.