Renaming variables in win_regedit module to make more sense with actions that are happening.
This commit is contained in:
parent
5a2a22bf68
commit
e84666fd74
2 changed files with 46 additions and 46 deletions
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -25,25 +25,25 @@ DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
module: win_regedit
|
module: win_regedit
|
||||||
version_added: "2.0"
|
version_added: "2.0"
|
||||||
short_description: Add, Edit, or Remove Registry Key
|
short_description: Add, Edit, or Remove Registry Value
|
||||||
description:
|
description:
|
||||||
- Add, Edit, or Remove Registry Key using ItemProperties Cmdlets
|
- Add, Edit, or Remove Registry Value using ItemProperties Cmdlets
|
||||||
options:
|
options:
|
||||||
name:
|
name:
|
||||||
description:
|
description:
|
||||||
- Name of Registry Key
|
- Name of Registry Value
|
||||||
required: true
|
required: true
|
||||||
default: null
|
default: null
|
||||||
aliases: []
|
aliases: []
|
||||||
value:
|
data:
|
||||||
description:
|
description:
|
||||||
- Value of Registry Key
|
- Registry Value Data
|
||||||
required: false
|
required: false
|
||||||
default: null
|
default: null
|
||||||
aliases: []
|
aliases: []
|
||||||
valuetype:
|
type:
|
||||||
description:
|
description:
|
||||||
- Type of Registry Key
|
- Registry Value Data Type
|
||||||
required: false
|
required: false
|
||||||
choices:
|
choices:
|
||||||
- binary
|
- binary
|
||||||
|
@ -56,13 +56,13 @@ options:
|
||||||
aliases: []
|
aliases: []
|
||||||
path:
|
path:
|
||||||
description:
|
description:
|
||||||
- Path of Registry Key
|
- Path of Registry Value
|
||||||
required: true
|
required: true
|
||||||
default: null
|
default: null
|
||||||
aliases: []
|
aliases: []
|
||||||
state:
|
state:
|
||||||
description:
|
description:
|
||||||
- State of Registry Key
|
- State of Registry Value
|
||||||
required: false
|
required: false
|
||||||
choices:
|
choices:
|
||||||
- present
|
- present
|
||||||
|
@ -73,29 +73,28 @@ author: "Adam Keech (@smadam813), Josh Ludwig (@joshludwig)"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
# Add Registry Key (Default is String)
|
# Add Registry Value (Default is String)
|
||||||
win_regedit:
|
win_regedit:
|
||||||
name: testkey
|
name: testvalue
|
||||||
value: 1337
|
data: 1337
|
||||||
path: HKCU:\Software\MyCompany
|
path: HKCU:\Software\MyCompany
|
||||||
|
|
||||||
# Add Registry Key with Type DWord
|
# Add Registry Value with Type DWord
|
||||||
win_regedit:
|
win_regedit:
|
||||||
name: testkey
|
name: testvalue
|
||||||
value: 1337
|
data: 1337
|
||||||
valuetype: dword
|
type: dword
|
||||||
path: HKCU:\Software\MyCompany
|
path: HKCU:\Software\MyCompany
|
||||||
|
|
||||||
# Edit Registry Key called testkey
|
# Edit Registry Value called testvalue
|
||||||
win_regedit:
|
win_regedit:
|
||||||
name: testkey
|
name: testvalue
|
||||||
value: 8008
|
data: 8008
|
||||||
path: HKCU:\Software\MyCompany
|
path: HKCU:\Software\MyCompany
|
||||||
|
|
||||||
# Remove Registry Key called testkey
|
# Remove Registry Value called testvalue
|
||||||
win_regedit:
|
win_regedit:
|
||||||
name: testkey
|
name: testvalue
|
||||||
path: HKCU:\Software\MyCompany
|
path: HKCU:\Software\MyCompany
|
||||||
state: absent
|
state: absent
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue