Renaming variables in win_regedit module to make more sense with actions that are happening.

This commit is contained in:
Adam Keech 2015-07-01 09:53:35 -04:00 committed by Matt Clay
parent 907fa20035
commit 1710d1aa0c
2 changed files with 46 additions and 46 deletions

View file

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

View file

@ -25,25 +25,25 @@ DOCUMENTATION = '''
---
module: win_regedit
version_added: "2.0"
short_description: Add, Edit, or Remove Registry Key
short_description: Add, Edit, or Remove Registry Value
description:
- Add, Edit, or Remove Registry Key using ItemProperties Cmdlets
- Add, Edit, or Remove Registry Value using ItemProperties Cmdlets
options:
name:
description:
- Name of Registry Key
- Name of Registry Value
required: true
default: null
aliases: []
value:
data:
description:
- Value of Registry Key
- Registry Value Data
required: false
default: null
aliases: []
valuetype:
type:
description:
- Type of Registry Key
- Registry Value Data Type
required: false
choices:
- binary
@ -56,13 +56,13 @@ options:
aliases: []
path:
description:
- Path of Registry Key
- Path of Registry Value
required: true
default: null
aliases: []
state:
description:
- State of Registry Key
- State of Registry Value
required: false
choices:
- present
@ -73,29 +73,28 @@ author: "Adam Keech (@smadam813), Josh Ludwig (@joshludwig)"
'''
EXAMPLES = '''
# Add Registry Key (Default is String)
# Add Registry Value (Default is String)
win_regedit:
name: testkey
value: 1337
name: testvalue
data: 1337
path: HKCU:\Software\MyCompany
# Add Registry Key with Type DWord
# Add Registry Value with Type DWord
win_regedit:
name: testkey
value: 1337
valuetype: dword
name: testvalue
data: 1337
type: dword
path: HKCU:\Software\MyCompany
# Edit Registry Key called testkey
# Edit Registry Value called testvalue
win_regedit:
name: testkey
value: 8008
name: testvalue
data: 8008
path: HKCU:\Software\MyCompany
# Remove Registry Key called testkey
# Remove Registry Value called testvalue
win_regedit:
name: testkey
name: testvalue
path: HKCU:\Software\MyCompany
state: absent
'''