Registry Key Creator - Updated 6/2019

<# .SYNOPSIS     Script to create new registry key. ScriptsbyScott.comDESCRIPTION    This can be used to check for key path and then create the key path.   This can easily be embedded in an invoke-command statment to create  regisry values on multiple remote systems.EXAMPLE     F

 
 
 
 
 
(0)
584 times
Add to favorites
Operating System
7/25/2019
E-mail Twitter del.icio.us Digg Facebook
  • Script does not work as expected.
    2 Posts | Last post June 26, 2019
    • jrv
      The Try/Catch does not work.
      
      
    • Works now
  • Why are there reurns statements in a simple script?
    2 Posts | Last post June 26, 2019
    • jrv
      The are not needed for any reason by the code.
      
      It is a good practice to not use double quotes when declaring static strings.
      
    • Changed to single quotes '
  • I tnik this is what you are trying to do.
    2 Posts | Last post June 26, 2019
    • jrv
      $path = 'HKLM:\HARDWARE\DESCRIPTION\System'
      $newKey = 'MyNewKeyName'
          
      $newValueName = 'myNewValue'
      $newValue = 245
      $dataType = 'DWORD'
      
      Try {
          $key = New-Item -Path $path -Name $newKey -Force -ErrorAction Stop 
          $key | New-ItemProperty -Name $newValueName -Value $newValue -PropertyType $dataType -ErrorAction Stop
      }
      Catch {
          Throw $_
      }
      
    • Updated with -ErrorAction Stop