Advertisement
upz

Set-RegItem

upz
Mar 10th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Set-RegItem
  2. {
  3. PARAM
  4. (
  5.     [string]$path,
  6.     [string]$name,
  7.     $value,
  8.     [ValidateSet('string',
  9.                 'ExpandString',
  10.                 'Binary',
  11.                 'DWord',
  12.                 'MultiString',
  13.                 'Qword',
  14.                 'Unknown')]
  15.     [string]$valuetype = 'string'
  16. )
  17.    
  18.     $test = Get-ItemProperty -Path $path -Name $name -ErrorAction SilentlyContinue
  19.     if ($test -ne $null)
  20.     {
  21.         if ((Get-ItemPropertyValue -Path $path -Name $name) -ne $value)
  22.         {
  23.             Remove-ItemProperty -Path $path -Name $name -Force
  24.             New-ItemProperty -Path $path -Name $name -Value $value -PropertyType $valuetype | Out-Null
  25.             return "$name changede to value $value"
  26.         }
  27.         else
  28.         {
  29.             return "$name exist with value $value"
  30.         }
  31.     }
  32.     else
  33.     {
  34.         New-ItemProperty -Path $path -Name $name -Value $value -PropertyType $valuetype | Out-Null
  35.         return "$name Created with value $value of type $valuetype"
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement