{"id":7881,"date":"2020-11-16T12:12:51","date_gmt":"2020-11-16T17:12:51","guid":{"rendered":"https:\/\/jdhitsolutions.com\/blog\/?p=7881"},"modified":"2020-11-16T12:12:57","modified_gmt":"2020-11-16T17:12:57","slug":"answering-the-powershell-registered-user-challenge","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7881\/answering-the-powershell-registered-user-challenge\/","title":{"rendered":"Answering the PowerShell Registered User Challenge"},"content":{"rendered":"\n<p>A few weeks ago, an Iron Scripter PowerShell <a href=\"https:\/\/ironscripter.us\/a-registered-powershell-challenge\/\" target=\"_blank\" rel=\"noreferrer noopener\">challenge <\/a>was issued. This was a beginner to intermediate level challenge to get and set the registered user and\/or organization values. These challenges, and solutions such as mine, aren't intended to production-ready tools. Instead, you should use them as learning vehicles to advance your PowerShell scripting skills. The concepts and techniques are more important than the actual result. Feel free to stop reading and try your hand at the challenge.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Read the Registry<\/h2>\n\n\n\n<p>The information for registered user and organization is stored in the registry. You can use Get-ItemProperty.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"221\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-1024x221.png\" alt=\"\" class=\"wp-image-7882\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-1024x221.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-300x65.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-768x165.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-1536x331.png 1536w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-850x183.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem.png 2029w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The cmdlet returns extra information, so you might want to be more selective.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Get-ItemProperty -Path \"HKLM:\\Software\\Microsoft\\Windows NT\\CurrentVersion\" -Name registered* |\nSelect-Object -property Registered*<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"169\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem2-1024x169.png\" alt=\"\" class=\"wp-image-7883\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem2-1024x169.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem2-300x49.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem2-768x127.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem2-1536x253.png 1536w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem2-850x140.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem2.png 1729w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Another option is to use Get-ItemPropertyValue to retrieve the value alone.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Get-ItemPropertyValue -Path \"HKLM:\\Software\\Microsoft\\Windows NT\\CurrentVersion\" -Name registeredowner,registeredorganization<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"966\" height=\"161\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-itemvalue.png\" alt=\"\" class=\"wp-image-7884\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-itemvalue.png 966w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-itemvalue-300x50.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-itemvalue-768x128.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-itemvalue-850x142.png 850w\" sizes=\"auto, (max-width: 966px) 100vw, 966px\" \/><\/figure>\n\n\n\n<p>With these ideas in mind, here is a simple function to get the necessary information from the local computer.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Function Get-RegisteredUserSimple {\n    Param()\n\n    $path = \"HKLM:\\Software\\Microsoft\\Windows NT\\CurrentVersion\"\n    Get-ItemProperty -Path $path | \n    Select-Object -Property RegisteredOwner,RegisteredOrganization,\n    @{Name=\"Computername\";Expression={$env:computername}}\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"921\" height=\"258\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-reguser-simple.png\" alt=\"\" class=\"wp-image-7885\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-reguser-simple.png 921w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-reguser-simple-300x84.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-reguser-simple-768x215.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-reguser-simple-850x238.png 850w\" sizes=\"auto, (max-width: 921px) 100vw, 921px\" \/><\/figure>\n\n\n\n<p>Sometimes, the use of Select-Object can get in the way of clarity.  That's why I tend to define custom objects like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Function Get-RegisteredUserBasic {\n    [cmdletbinding()]\n    Param()\n\n    $path = \"HKLM:\\Software\\Microsoft\\Windows NT\\CurrentVersion\"\n    $reg = Get-ItemProperty -Path $path\n\n    [pscustomobject]@{\n        RegisteredUser         = $reg.RegisteredOwner\n        RegisteredOrganization = $reg.RegisteredOrganization\n        Computername           = $env:COMPUTERNAME\n    }\n}<\/code><\/pre>\n\n\n\n<p>The output will be the same.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Set the Registry<\/h2>\n\n\n\n<p>What about setting new values? For that task we can use Set-ItemProperty. I'm trusting you'll read full help and examples for all of the commands I'm using. Here's my relatively simple function to set the owner and\/or organization values.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Function Set-RegisteredUserBasic {\n    [cmdletbinding(SupportsShouldProcess)]\n    Param(\n        [Parameter()]\n        [alias(\"user\")]\n        [ValidateNotNullOrEmpty()]\n        [string]$RegisteredUser,\n\n        [Parameter()]\n        [alias(\"org\")]\n        [ValidateNotNullOrEmpty()]\n        [string]$RegisteredOrganization,\n\n        [switch]$Passthru\n    )\n\n    #registry path\n    $path = \"HKLM:\\Software\\Microsoft\\Windows NT\\CurrentVersion\"\n\n    #a flag variable to indicate if a change was made\n    $set = $False\n\n    #Only set property if something was entered\n    if ($RegisteredUser) {\n        Write-Verbose \"Setting Registered Owner to $RegisteredUser\"\n        Set-ItemProperty -Path $path -Name \"RegisteredOwner\" -Value $RegisteredUser\n        $set = $True\n    }\n\n    #Only set property if something was entered\n    if ($RegisteredOrganization) {\n        Write-Verbose \"Setting Registered Organization to $RegisteredOrganization\"\n        Set-ItemProperty -Path $path -Name \"RegisteredOrganization\" -Value $RegisteredOrganization\n        $set = $True\n    }\n\n    #passthru if something was set\n    if ($set -AND $passthru) {\n\n        $reg = Get-ItemProperty $path\n        [pscustomobject]@{\n            RegisteredUser         = $reg.RegisteredOwner\n            RegisteredOrganization = $reg.RegisteredOrganization\n            Computername           = $env:COMPUTERNAME\n        }\n    } #if passthru\n}<\/code><\/pre>\n\n\n\n<p>I've included a very intermediate-level features such as support for -WhatIf, some parameter validation and parameter aliases. Because I configured cmdletbinding to use \"SupportsShouldProcess\", I'll automatically get the WhatIf and Confirm parameters. Even better, any command that I call will automatically consume the parameter values. In my function, Set-ItemProperty supports -WhatIf. But I don't have to do anything special.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"66\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-basic-whatif-1024x66.png\" alt=\"\" class=\"wp-image-7887\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-basic-whatif-1024x66.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-basic-whatif-300x19.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-basic-whatif-768x50.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-basic-whatif-1536x100.png 1536w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-basic-whatif-2048x133.png 2048w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-basic-whatif-850x55.png 850w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>My code is using a -Passthru switch parameter to get value, if specified.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"170\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-basic-1024x170.png\" alt=\"\" class=\"wp-image-7888\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-basic-1024x170.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-basic-300x50.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-basic-768x128.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-basic-850x141.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-basic.png 1529w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>I don't have any real error-handling in this function. In order to modify the this part of the registry you need to be running PowerShell as administrator. If I wasn't, Set-ItemProperty would throw an exception, which I would be fine with. One thing I could do is require administrator access. <\/p>\n\n\n\n<p>The functions have to live in a .ps1 file and then be dot-sourced. Let's leave modules out of the discussion. At the top of the .ps1 file I can add these require statements:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">#requires -version 5.1\n#requires -RunAsAdministrator<\/code><\/pre>\n\n\n\n<p>When the user dot sources the file, if they are not running as Administrator, PowerShell will throw an exception.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Taking the Next Step<\/h2>\n\n\n\n<p>My basic functions work fine when working with the localhost. And I think they would have met the basic requirements of the challenge. But the challenge had extra features.  Let's look at those.<\/p>\n\n\n\n<p>When using the registry provider as I am, this only works on the local computer. To access the registry remotely, you can use PowerShell remoting.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\"> Invoke-Command -scriptblock {\n Get-ItemProperty -Path \"HKLM:\\Software\\Microsoft\\Windows NT\\CurrentVersion\" -Name registered*\n } -computername win10 -credential $artd | Select-Object -property Registered*,PSComputername<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"211\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-remote-1024x211.png\" alt=\"\" class=\"wp-image-7890\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-remote-1024x211.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-remote-300x62.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-remote-768x158.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-remote-1536x317.png 1536w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-remote-850x175.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-remote.png 1557w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>I can take this basic idea and turn it into an advanced PowerShell function. By the way, I always start with a command-line solution like this first. Once I have it working, then I can begin building a function around it. If you are new to PowerShell I recommend this approach.  <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Building a Remoting Function<\/h2>\n\n\n\n<p>Here's my get function.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Function Get-RegisteredUser {\n    [cmdletbinding()]\n    Param(\n        [Parameter(Position = 0, ValueFromPipeline)]\n        [alias(\"cn\")]\n        [string[]]$Computername = $env:COMPUTERNAME,\n        [pscredential]$Credential,\n        [int32]$ThrottleLimit,\n        [switch]$UseSSL\n    )\n\n    Begin {\n        Write-Verbose \"Starting $($MyInvocation.MyCommand)\"\n        #a scriptblock to run remotely\n        $sb = {\n            $path = \"HKLM:\\Software\\Microsoft\\Windows NT\\CurrentVersion\"\n            $reg = Get-ItemProperty -Path $path\n\n            [pscustomobject]@{\n                PSTypeName             = \"PSRegisteredUser\"\n                RegisteredUser         = $reg.RegisteredOwner\n                RegisteredOrganization = $reg.RegisteredOrganization\n                Computername           = $env:COMPUTERNAME\n            }\n        }\n\n        $PSBoundParameters.Add(\"Scriptblock\", $sb)\n        $PSBoundParameters.Add(\"HideComputername\", $True)\n    }\n    Process {\n        #add the default computername if nothing was specified\n        if (-NOT $PSBoundParameters.ContainsKey(\"computername\")) {\n            Write-Verbose \"Querying localhost\"\n            $PSBoundParameters.Computername = $Computername\n        }\n        Invoke-Command @PSBoundParameters | ForEach-Object {\n            #create a custom object\n            [pscustomobject]@{\n                PSTypeName   = \"psRegisteredUser\"\n                Computername = $_.Computername\n                User         = $_.RegisteredUser\n                Organization = $_.RegisteredOrganization\n                Date         = (Get-Date)\n            }\n        }\n    } #process\n    End {\n        Write-Verbose \"Ending $($MyInvocation.MyCommand)\"\n    }\n}<\/code><\/pre>\n\n\n\n<p>I've moved all of the registry reading code inside a scriptblock which I'll run with Invoke-Command. The function parameters and the same as Invoke-Command so I can splat the built-in $PSBoundParameters hashtable to the command. Although, you'll see that I'm tweaking it a bit to add parameters.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$PSBoundParameters.Add(\"Scriptblock\", $sb)\n$PSBoundParameters.Add(\"HideComputername\", $True)<\/code><\/pre>\n\n\n\n<p>When the command runs remotely, it sends a serialized object back to me. I'm creating a custom object for each result.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\"> Invoke-Command @PSBoundParameters | ForEach-Object {\n            #create a custom object\n            [pscustomobject]@{\n                PSTypeName   = \"psRegisteredUser\"\n                Computername = $_.Computername\n                User         = $_.RegisteredUser\n                Organization = $_.RegisteredOrganization\n                Date         = (Get-Date)\n            }\n        }<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"288\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-remote2-1024x288.png\" alt=\"\" class=\"wp-image-7891\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-remote2-1024x288.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-remote2-300x84.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-remote2-768x216.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-remote2-850x239.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-remote2.png 1318w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Adding Formatting<\/h2>\n\n\n\n<p>You'll notice that I defined a typename for the custom object. This is so that I can create a custom format file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Get-RegisteredUser | \nNew-PSFormatXML -path c:\\scripts\\registered.format.ps1xml -GroupBy Computername -Properties User,Organization,Date\n<\/code><\/pre>\n\n\n\n<p>New-PSFormatXML is from the <a href=\"https:\/\/github.com\/jdhitsolutions\/PSScriptTools\" target=\"_blank\" rel=\"noreferrer noopener\">PSScriptTools <\/a>module. I can edit the xml file to meet my needs. In my case, I set specific column widths and formatted the Date value.<\/p>\n\n\n\n<pre class=\"wp-block-code\" title=\"registered.format.ps1xml\"><code lang=\"xml\" class=\"language-xml\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?>\n&lt;!--\nFormat type data generated 11\/16\/2020 11:32:51 by PROSPERO\\Jeff\n\nThis file was created using the New-PSFormatXML command that is part\nof the PSScriptTools module.\nhttps:\/\/github.com\/jdhitsolutions\/PSScriptTools\n-->\n&lt;Configuration>\n  &lt;ViewDefinitions>\n    &lt;View>\n      &lt;!--Created 11\/16\/2020 11:32:51 by PROSPERO\\Jeff-->\n      &lt;Name>default&lt;\/Name>\n      &lt;ViewSelectedBy>\n        &lt;TypeName>psRegisteredUser&lt;\/TypeName>\n      &lt;\/ViewSelectedBy>\n      &lt;GroupBy>\n        &lt;!--\n            You can also use a scriptblock to define a custom property name.\n            You must have a Label tag.\n            &lt;ScriptBlock>$_.machinename.toUpper()&lt;\/ScriptBlock>\n            &lt;Label>Computername&lt;\/Label>\n\n            Use &lt;Label> to set the displayed value.\n-->\n        &lt;PropertyName>Computername&lt;\/PropertyName>\n        &lt;Label>Computername&lt;\/Label>\n      &lt;\/GroupBy>\n      &lt;TableControl>\n        &lt;!--Delete the AutoSize node if you want to use the defined widths.\n        &lt;AutoSize \/>-->\n        &lt;TableHeaders>\n          &lt;TableColumnHeader>\n            &lt;Label>User&lt;\/Label>\n            &lt;Width>18&lt;\/Width>\n            &lt;Alignment>left&lt;\/Alignment>\n          &lt;\/TableColumnHeader>\n          &lt;TableColumnHeader>\n            &lt;Label>Organization&lt;\/Label>\n            &lt;Width>20&lt;\/Width>\n            &lt;Alignment>left&lt;\/Alignment>\n          &lt;\/TableColumnHeader>\n          &lt;TableColumnHeader>\n            &lt;Label>Date&lt;\/Label>\n            &lt;Width>10&lt;\/Width>\n            &lt;Alignment>right&lt;\/Alignment>\n          &lt;\/TableColumnHeader>\n        &lt;\/TableHeaders>\n        &lt;TableRowEntries>\n          &lt;TableRowEntry>\n            &lt;TableColumnItems>\n              &lt;!--\n            By default the entries use property names, but you can replace them with scriptblocks.\n            &lt;ScriptBlock>$_.foo \/1mb -as [int]&lt;\/ScriptBlock>\n-->\n              &lt;TableColumnItem>\n                &lt;PropertyName>User&lt;\/PropertyName>\n              &lt;\/TableColumnItem>\n              &lt;TableColumnItem>\n                &lt;PropertyName>Organization&lt;\/PropertyName>\n              &lt;\/TableColumnItem>\n              &lt;TableColumnItem>\n                &lt;ScriptBlock>$_.Date.ToShortDateString()&lt;\/ScriptBlock>\n              &lt;\/TableColumnItem>\n            &lt;\/TableColumnItems>\n          &lt;\/TableRowEntry>\n        &lt;\/TableRowEntries>\n      &lt;\/TableControl>\n    &lt;\/View>\n  &lt;\/ViewDefinitions>\n&lt;\/Configuration><\/code><\/pre>\n\n\n\n<p>I then import the file into my session.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Update-FormatData C:\\scripts\\registered.format.ps1xml<\/code><\/pre>\n\n\n\n<p>Now, when I run the function I get better formatted results.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"674\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-remote-formatted-1024x674.png\" alt=\"\" class=\"wp-image-7892\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-remote-formatted-1024x674.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-remote-formatted-300x197.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-remote-formatted-768x505.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-remote-formatted-350x230.png 350w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-remote-formatted-850x559.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-remote-formatted.png 1274w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Setting Remote Registry Values<\/h2>\n\n\n\n<p>I'll take a similar approach to setting the registry values remotely. I have to have admin access to connect remotely so I don't have to worry about not having access. My set function uses the same concepts and techniques as the get function.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Function Set-RegisteredUser {\n    [cmdletbinding(SupportsShouldProcess)]\n    Param(\n        [Parameter()]\n        [alias(\"user\")]\n        [ValidateNotNullOrEmpty()]\n        [string]$RegisteredUser,\n\n        [Parameter()]\n        [alias(\"org\")]\n        [ValidateNotNullOrEmpty()]\n        [string]$RegisteredOrganization,\n\n        [Parameter(ValueFromPipeline)]\n        [alias(\"cn\")]\n        [string[]]$Computername = $env:COMPUTERNAME,\n\n        [pscredential]$Credential,\n\n        [switch]$Passthru\n    )\n\n    Begin {\n        Write-Verbose \"Starting $($myinvocation.MyCommand)\"\n\n        $sb = {\n            [cmdletbinding()]\n            &lt;#\n            PowerShell doesn't serialize a switch type very well so I'll\n            make passthru a boolean. Although in this situation, instead of\n            passing parameters I could have referenced the variables from\n            the local host as I'm doing with -Verbose and -WhatIf\n            #>\n            Param(\n                [string]$RegisteredUser,\n                [string]$RegisteredOrganization,\n                [bool]$Passthru\n            )\n\n            $VerbosePreference = $using:verbosepreference\n            $WhatIfPreference = $using:WhatifPreference\n\n            #registry path\n            $path = \"HKLM:\\Software\\Microsoft\\Windows NT\\CurrentVersion\"\n            Write-Verbose \"[$($env:COMPUTERNAME)] Using registry path $path\"\n            #a flag variable to indicate if a change was made\n            $set = $False\n\n            #Only set property if something was entered\n            if ($RegisteredUser) {\n                Write-Verbose \"[$($env:COMPUTERNAME)] Setting Registered Owner to $RegisteredUser\"\n                #define my own -WhatIf\n                if ($pscmdlet.ShouldProcess($env:COMPUTERNAME, \"Set registered user to $RegisteredUser\")) {\n                    Set-ItemProperty -Path $path -Name \"RegisteredOwner\" -Value $RegisteredUser\n                    $set = $True\n                }\n            }\n\n            #Only set property if something was entered\n            if ($RegisteredOrganization) {\n                Write-Verbose \"[$($env:COMPUTERNAME)] Setting Registered Organization to $RegisteredOrganization\"\n                if ($pscmdlet.ShouldProcess($env:COMPUTERNAME, \"Set registered organization to $RegisteredOrganization\")) {\n                    Set-ItemProperty -Path $path -Name \"RegisteredOrganization\" -Value $RegisteredOrganization\n                    $set = $True\n                }\n            }\n\n            #passthru if something was set\n            if ($set -AND $passthru) {\n                $reg = Get-ItemProperty $path\n                [pscustomobject]@{\n                    PSTypeName   = \"PSRegisteredUser\"\n                    Computername = $env:COMPUTERNAME\n                    User         = $reg.RegisteredOwner\n                    Organization = $reg.RegisteredOrganization\n                    Date         = Get-Date\n                }\n            } #if passthru\n\n        } #close scriptblock\n\n        $icmParams = @{\n            Scriptblock  = $sb\n            ArgumentList = @($RegisteredUser, $RegisteredOrganization, ($Passthru -as [bool]))\n            HideComputername = $True\n        }\n        if ($Credential) {\n            Write-Verbose \"Using credential for $($credential.username)\"\n            $icmParams.Add(\"Credential\", $credential)\n        }\n\n    } #begin\n    Process {\n        $icmParams.Computername = $Computername\n        Invoke-Command @icmParams | Select-Object -Property * -ExcludeProperty RunspaceID\n        #You could also create the custom object on this end as I did with Get-RegisteredUser\n    } #process\n\n    End {\n        Write-Verbose \"Ending $($myinvocation.MyCommand)\"\n    } #end\n}<\/code><\/pre>\n\n\n\n<p>There are a few things I want to point out. Remember, the scriptblock is running remotely but I need to pass values from my local session. My code is demonstrating a few techniques. <\/p>\n\n\n\n<p>First, the scriptblock is defined with parameters.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$sb = {\n    [cmdletbinding()]\n    &lt;#\n    PowerShell doesn't serialize a switch type very well so I'll\n    make passthru a boolean. Although in this situation, instead of\n    passing parameters I could have referenced the variables from\n    the local host as I'm doing with -Verbose and -WhatIf\n    #>\n    Param(\n        [string]$RegisteredUser,\n        [string]$RegisteredOrganization,\n        [bool]$Passthru\n    )<\/code><\/pre>\n\n\n\n<p>Later in my code I'll pass the local values to the scriptblock.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$icmParams = @{\n  Scriptblock  = $sb\n  ArgumentList = @($RegisteredUser, $RegisteredOrganization, ($Passthru -as [bool]))\n  HideComputername = $True\n}<\/code><\/pre>\n\n\n\n<p>The other approach is to employ the $using: prefix. This is how I am setting -Verbose and -Whatif in the remote scriptblock.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$VerbosePreference = $using:verbosepreference\n$WhatIfPreference = $using:WhatifPreference<\/code><\/pre>\n\n\n\n<p>In essence, I'm setting the remote preference variables to use the local values.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"207\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-remote-whatif-1024x207.png\" alt=\"\" class=\"wp-image-7894\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-remote-whatif-1024x207.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-remote-whatif-300x61.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-remote-whatif-768x155.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-remote-whatif-1536x310.png 1536w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-remote-whatif-850x171.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-remote-whatif.png 1933w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>In my function, instead of passing WhatIf to Set-ItemProperty, I'm defining my own WhatIf code to provide better information.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">if ($pscmdlet.ShouldProcess($env:COMPUTERNAME, \"Set registered user to $RegisteredUser\")) {\n    Set-ItemProperty -Path $path -Name \"RegisteredOwner\" -Value $RegisteredUser\n    $set = $True\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"258\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-remote-1024x258.png\" alt=\"\" class=\"wp-image-7895\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-remote-1024x258.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-remote-300x76.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-remote-768x193.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-remote-1536x387.png 1536w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-remote-850x214.png 850w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/set-reg-remote.png 1882w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>I could follow the same process as with my get function and define a true custom object that could use the same formatting file. I'll leave that exercise for you.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<p>I hope you'll try these functions out for yourself. Read the cmdlet help so that you understand why the code works. If you have any questions, please leave a comment. And I hope you'll keep an eye out for other Iron Scripter Challenges and try your hand.<\/p>\n\n\n\n<p>By the way, if you are looking for other ways to test your PowerShell skills, especially if you are a beginner,  you might want to grab a copy of <a href=\"https:\/\/leanpub.com\/psprimer\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">The PowerShell Practice Primer<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few weeks ago, an Iron Scripter PowerShell challenge was issued. This was a beginner to intermediate level challenge to get and set the registered user and\/or organization values. These challenges, and solutions such as mine, aren&#8217;t intended to production-ready tools. Instead, you should use them as learning vehicles to advance your PowerShell scripting skills&#8230;.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"New on the blog: Answering the #PowerShell Registered User Challenge ","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,8],"tags":[240,224,618,534,560],"class_list":["post-7881","post","type-post","status-publish","format-standard","hentry","category-powershell","category-scripting","tag-formatting","tag-function","tag-iron-scripter","tag-powershell","tag-registry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Answering the PowerShell Registered User Challenge &#8226; The Lonely Administrator<\/title>\n<meta name=\"description\" content=\"My solution and commentary on a recent Iron Scripter PowerShell challenge to get and set registry values for registered user and company.,\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/7881\/answering-the-powershell-registered-user-challenge\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Answering the PowerShell Registered User Challenge &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"My solution and commentary on a recent Iron Scripter PowerShell challenge to get and set registry values for registered user and company.,\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/7881\/answering-the-powershell-registered-user-challenge\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2020-11-16T17:12:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-11-16T17:12:57+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-1024x221.png\" \/>\n<meta name=\"author\" content=\"Jeffery Hicks\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:site\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeffery Hicks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7881\\\/answering-the-powershell-registered-user-challenge\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7881\\\/answering-the-powershell-registered-user-challenge\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Answering the PowerShell Registered User Challenge\",\"datePublished\":\"2020-11-16T17:12:51+00:00\",\"dateModified\":\"2020-11-16T17:12:57+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7881\\\/answering-the-powershell-registered-user-challenge\\\/\"},\"wordCount\":945,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7881\\\/answering-the-powershell-registered-user-challenge\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/11\\\/get-regitem-1024x221.png\",\"keywords\":[\"formatting\",\"Function\",\"Iron Scripter\",\"PowerShell\",\"Registry\"],\"articleSection\":[\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7881\\\/answering-the-powershell-registered-user-challenge\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7881\\\/answering-the-powershell-registered-user-challenge\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7881\\\/answering-the-powershell-registered-user-challenge\\\/\",\"name\":\"Answering the PowerShell Registered User Challenge &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7881\\\/answering-the-powershell-registered-user-challenge\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7881\\\/answering-the-powershell-registered-user-challenge\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/11\\\/get-regitem-1024x221.png\",\"datePublished\":\"2020-11-16T17:12:51+00:00\",\"dateModified\":\"2020-11-16T17:12:57+00:00\",\"description\":\"My solution and commentary on a recent Iron Scripter PowerShell challenge to get and set registry values for registered user and company.,\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7881\\\/answering-the-powershell-registered-user-challenge\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7881\\\/answering-the-powershell-registered-user-challenge\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7881\\\/answering-the-powershell-registered-user-challenge\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/11\\\/get-regitem.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/11\\\/get-regitem.png\",\"width\":2029,\"height\":437},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7881\\\/answering-the-powershell-registered-user-challenge\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Answering the PowerShell Registered User Challenge\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/\",\"name\":\"The Lonely Administrator\",\"description\":\"Practical Advice for the Automating IT Pro\",\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\",\"name\":\"Jeffery Hicks\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"caption\":\"Jeffery Hicks\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Answering the PowerShell Registered User Challenge &#8226; The Lonely Administrator","description":"My solution and commentary on a recent Iron Scripter PowerShell challenge to get and set registry values for registered user and company.,","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7881\/answering-the-powershell-registered-user-challenge\/","og_locale":"en_US","og_type":"article","og_title":"Answering the PowerShell Registered User Challenge &#8226; The Lonely Administrator","og_description":"My solution and commentary on a recent Iron Scripter PowerShell challenge to get and set registry values for registered user and company.,","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7881\/answering-the-powershell-registered-user-challenge\/","og_site_name":"The Lonely Administrator","article_published_time":"2020-11-16T17:12:51+00:00","article_modified_time":"2020-11-16T17:12:57+00:00","og_image":[{"url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-1024x221.png","type":"","width":"","height":""}],"author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7881\/answering-the-powershell-registered-user-challenge\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7881\/answering-the-powershell-registered-user-challenge\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Answering the PowerShell Registered User Challenge","datePublished":"2020-11-16T17:12:51+00:00","dateModified":"2020-11-16T17:12:57+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7881\/answering-the-powershell-registered-user-challenge\/"},"wordCount":945,"commentCount":1,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7881\/answering-the-powershell-registered-user-challenge\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-1024x221.png","keywords":["formatting","Function","Iron Scripter","PowerShell","Registry"],"articleSection":["PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/7881\/answering-the-powershell-registered-user-challenge\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7881\/answering-the-powershell-registered-user-challenge\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7881\/answering-the-powershell-registered-user-challenge\/","name":"Answering the PowerShell Registered User Challenge &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7881\/answering-the-powershell-registered-user-challenge\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7881\/answering-the-powershell-registered-user-challenge\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem-1024x221.png","datePublished":"2020-11-16T17:12:51+00:00","dateModified":"2020-11-16T17:12:57+00:00","description":"My solution and commentary on a recent Iron Scripter PowerShell challenge to get and set registry values for registered user and company.,","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7881\/answering-the-powershell-registered-user-challenge\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/7881\/answering-the-powershell-registered-user-challenge\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7881\/answering-the-powershell-registered-user-challenge\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/11\/get-regitem.png","width":2029,"height":437},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7881\/answering-the-powershell-registered-user-challenge\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"Answering the PowerShell Registered User Challenge"}]},{"@type":"WebSite","@id":"https:\/\/jdhitsolutions.com\/blog\/#website","url":"https:\/\/jdhitsolutions.com\/blog\/","name":"The Lonely Administrator","description":"Practical Advice for the Automating IT Pro","publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jdhitsolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9","name":"Jeffery Hicks","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","caption":"Jeffery Hicks"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":8107,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8107\/scripting-challenge-meetup\/","url_meta":{"origin":7881,"position":0},"title":"Scripting Challenge Meetup","author":"Jeffery Hicks","date":"February 1, 2021","format":false,"excerpt":"As you probably know, I am the PowerShell problem master behind the challenges from the Iron Scripter site. Solving a PowerShell scripting challenge is a great way to test your skills and expand your knowledge. The final result is merely a means to an end. How you get there and\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/02\/rubik.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":49,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/49\/reading-the-registry-in-powershell\/","url_meta":{"origin":7881,"position":1},"title":"Reading the Registry in PowerShell","author":"Jeffery Hicks","date":"August 26, 2006","format":false,"excerpt":"One of the great PowerShell features is that it treats the registry like any other location or directory. In PowerShell you can connect directly to the registry and navigate the key hierarchy just as if it as a logical drive with folders. I have a very brief demonstration script you\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":9018,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9018\/an-iron-scripter-warm-up-solution\/","url_meta":{"origin":7881,"position":2},"title":"An Iron Scripter Warm-Up Solution","author":"Jeffery Hicks","date":"May 6, 2022","format":false,"excerpt":"We just wrapped up the 2022 edition of the PowerShell+DevOps Global Summit. It was terrific to be with passionate PowerShell professionals again. The culmination of the event is the Iron Scripter Challenge. You can learn more about this year's event and winner here. But there is more to the Iron\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1454,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1454\/teched-atlanta-managing-the-registry-with-powershell\/","url_meta":{"origin":7881,"position":3},"title":"TechEd Atlanta &#8211; Managing the Registry with PowerShell","author":"Jeffery Hicks","date":"May 23, 2011","format":false,"excerpt":"My second TechEd talk was about managing the registry with Windows PowerShell. If you were in the session you know that I stressed heavily using the PowerShell provider and cmdlets. For remote computers, leverage PowerShell's remoting infrastructure. But I also discussed using the \"raw\" .NET classes as well as WMI\u2026","rel":"","context":"In &quot;Conferences&quot;","block_context":{"text":"Conferences","link":"https:\/\/jdhitsolutions.com\/blog\/category\/conferences\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":53,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/53\/writing-the-registry-in-powershell\/","url_meta":{"origin":7881,"position":4},"title":"Writing the Registry in PowerShell","author":"Jeffery Hicks","date":"September 22, 2006","format":false,"excerpt":"Last month I showed you how to read the registry in PowerShell. I went through a script that would read the registered owner and organization. Now I'll show you how to change those properties in PowerShell. Here's the script, which is also available for download from my script library. Here's\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":7489,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7489\/powershell-word-play\/","url_meta":{"origin":7881,"position":5},"title":"PowerShell Word Play","author":"Jeffery Hicks","date":"May 19, 2020","format":false,"excerpt":"A few weeks ago an Iron Scripter PowerShell challenge was issued that involved playing with words and characters. Remember, the Iron Scripter challenges aren't intended to create meaningful, production worthy code. They are designed to help you learn PowerShell fundamentals and scripting techniques. This particular challenge was aimed at beginner\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/doublechar.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/doublechar.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/doublechar.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/doublechar.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/doublechar.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/doublechar.png?resize=1400%2C800&ssl=1 4x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/7881","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=7881"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/7881\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=7881"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=7881"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=7881"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}