Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Set-RegItem
- {
- PARAM
- (
- [string]$path,
- [string]$name,
- $value,
- [ValidateSet('string',
- 'ExpandString',
- 'Binary',
- 'DWord',
- 'MultiString',
- 'Qword',
- 'Unknown')]
- [string]$valuetype = 'string'
- )
- $test = Get-ItemProperty -Path $path -Name $name -ErrorAction SilentlyContinue
- if ($test -ne $null)
- {
- if ((Get-ItemPropertyValue -Path $path -Name $name) -ne $value)
- {
- Remove-ItemProperty -Path $path -Name $name -Force
- New-ItemProperty -Path $path -Name $name -Value $value -PropertyType $valuetype | Out-Null
- return "$name changede to value $value"
- }
- else
- {
- return "$name exist with value $value"
- }
- }
- else
- {
- New-ItemProperty -Path $path -Name $name -Value $value -PropertyType $valuetype | Out-Null
- return "$name Created with value $value of type $valuetype"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement