|
|
@ -27,7 +27,7 @@ Set-Attr $result "changed" $false;
|
|
|
|
|
|
|
|
|
|
|
|
If ($params.name)
|
|
|
|
If ($params.name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$registryKeyName = $params.name
|
|
|
|
$registryValueName = $params.name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Else
|
|
|
|
Else
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -47,39 +47,39 @@ Else
|
|
|
|
$state = "present"
|
|
|
|
$state = "present"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
If ($params.value)
|
|
|
|
If ($params.data)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$registryKeyValue = $params.value
|
|
|
|
$registryValueData = $params.data
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ElseIf ($state -eq "present")
|
|
|
|
ElseIf ($state -eq "present")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Fail-Json $result "missing required argument: value"
|
|
|
|
Fail-Json $result "missing required argument: data"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
If ($params.valuetype)
|
|
|
|
If ($params.type)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$registryValueType = $params.valuetype.ToString().ToLower()
|
|
|
|
$registryDataType = $params.type.ToString().ToLower()
|
|
|
|
$validRegistryValueTypes = "binary", "dword", "expandstring", "multistring", "string", "qword"
|
|
|
|
$validRegistryDataTypes = "binary", "dword", "expandstring", "multistring", "string", "qword"
|
|
|
|
If ($validRegistryValueTypes -notcontains $registryValueType)
|
|
|
|
If ($validRegistryDataTypes -notcontains $registryDataType)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Fail-Json $result "valuetype is $registryValueType; must be binary, dword, expandstring, multistring, string, or qword"
|
|
|
|
Fail-Json $result "type is $registryDataType; must be binary, dword, expandstring, multistring, string, or qword"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Else
|
|
|
|
Else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$registryValueType = "string"
|
|
|
|
$registryDataType = "string"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
If ($params.path)
|
|
|
|
If ($params.path)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
$registryKeyPath = $params.path
|
|
|
|
$registryValuePath = $params.path
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Else
|
|
|
|
Else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Fail-Json $result "missing required argument: path"
|
|
|
|
Fail-Json $result "missing required argument: path"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Function Test-RegistryValue {
|
|
|
|
Function Test-RegistryValueData {
|
|
|
|
Param (
|
|
|
|
Param (
|
|
|
|
[parameter(Mandatory=$true)]
|
|
|
|
[parameter(Mandatory=$true)]
|
|
|
|
[ValidateNotNullOrEmpty()]$Path,
|
|
|
|
[ValidateNotNullOrEmpty()]$Path,
|
|
|
@ -96,16 +96,16 @@ Function Test-RegistryValue {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if($state -eq "present") {
|
|
|
|
if($state -eq "present") {
|
|
|
|
if (Test-Path $registryKeyPath) {
|
|
|
|
if (Test-Path $registryValuePath) {
|
|
|
|
if (Test-RegistryValue -Path $registryKeyPath -Value $registryKeyName)
|
|
|
|
if (Test-RegistryValueData -Path $registryValuePath -Value $registryValueName)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
# Changes Type and Value
|
|
|
|
# Changes Type and Value
|
|
|
|
If ((Get-Item $registryKeyPath).GetValueKind($registryKeyName) -ne $registryValueType)
|
|
|
|
If ((Get-Item $registryValuePath).GetValueKind($registryValueName) -ne $registryDataType)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Try
|
|
|
|
Try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Remove-ItemProperty -Path $registryKeyPath -Name $registryKeyName
|
|
|
|
Remove-ItemProperty -Path $registryValuePath -Name $registryValueName
|
|
|
|
New-ItemProperty -Path $registryKeyPath -Name $registryKeyName -Value $registryKeyValue -PropertyType $registryValueType
|
|
|
|
New-ItemProperty -Path $registryValuePath -Name $registryValueName -Value $registryValueData -PropertyType $registryDataType
|
|
|
|
$result.changed = $true
|
|
|
|
$result.changed = $true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Catch
|
|
|
|
Catch
|
|
|
@ -114,10 +114,10 @@ if($state -eq "present") {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# Only Changes Value
|
|
|
|
# Only Changes Value
|
|
|
|
ElseIf ((Get-ItemProperty -Path $registryKeyPath | Select-Object -ExpandProperty $registryKeyName) -ne $registryKeyValue)
|
|
|
|
ElseIf ((Get-ItemProperty -Path $registryValuePath | Select-Object -ExpandProperty $registryValueName) -ne $registryValueData)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Try {
|
|
|
|
Try {
|
|
|
|
Set-ItemProperty -Path $registryKeyPath -Name $registryKeyName -Value $registryKeyValue
|
|
|
|
Set-ItemProperty -Path $registryValuePath -Name $registryValueName -Value $registryValueData
|
|
|
|
$result.changed = $true
|
|
|
|
$result.changed = $true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Catch
|
|
|
|
Catch
|
|
|
@ -130,7 +130,7 @@ if($state -eq "present") {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Try
|
|
|
|
Try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
New-ItemProperty -Path $registryKeyPath -Name $registryKeyName -Value $registryKeyValue -PropertyType $registryValueType
|
|
|
|
New-ItemProperty -Path $registryValuePath -Name $registryValueName -Value $registryValueData -PropertyType $registryDataType
|
|
|
|
$result.changed = $true
|
|
|
|
$result.changed = $true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Catch
|
|
|
|
Catch
|
|
|
@ -143,7 +143,7 @@ if($state -eq "present") {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Try
|
|
|
|
Try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
New-Item $registryKeyPath -Force | New-ItemProperty -Name $registryKeyName -Value $registryKeyValue -Force -PropertyType $registryValueType
|
|
|
|
New-Item $registryValuePath -Force | New-ItemProperty -Name $registryValueName -Value $registryValueData -Force -PropertyType $registryDataType
|
|
|
|
$result.changed = $true
|
|
|
|
$result.changed = $true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Catch
|
|
|
|
Catch
|
|
|
@ -154,12 +154,12 @@ if($state -eq "present") {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (Test-Path $registryKeyPath)
|
|
|
|
if (Test-Path $registryValuePath)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (Test-RegistryValue -Path $registryKeyPath -Value $registryKeyName) {
|
|
|
|
if (Test-RegistryValueData -Path $registryValuePath -Value $registryValueName) {
|
|
|
|
Try
|
|
|
|
Try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Remove-ItemProperty -Path $registryKeyPath -Name $registryKeyName
|
|
|
|
Remove-ItemProperty -Path $registryValuePath -Name $registryValueName
|
|
|
|
$result.changed = $true
|
|
|
|
$result.changed = $true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Catch
|
|
|
|
Catch
|
|
|
@ -171,3 +171,4 @@ else
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Exit-Json $result
|
|
|
|
Exit-Json $result
|
|
|
|
|
|
|
|
|
|
|
|