-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from sbaerlocher/develop/0.0.7
add change
- Loading branch information
Showing
4 changed files
with
111 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!powershell | ||
|
||
# Copyright: (c) 2020, Simon Baerlocher <[email protected]> | ||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
#AnsibleRequires -CSharpUtil Ansible.Basic | ||
|
||
$spec = @{ | ||
options = @{ | ||
path = @{ type = 'str'; required = $true; } | ||
key = @{ type = 'str'; required = $true; aliases = 'key' } | ||
name = @{ type = 'str'; aliases = 'entry', 'value' } | ||
data = @{ type = 'raw' } | ||
type = @{ | ||
type = 'str' | ||
default = 'string' | ||
choices = 'none', 'binary', 'dword', 'expandstring', 'multistring', 'string', 'qword' | ||
aliases = 'datatype' | ||
} | ||
state = @{ type = 'str'; default = 'present'; choices = 'present', 'absent' } | ||
|
||
} | ||
supports_check_mode = $true | ||
} | ||
|
||
$module = [Ansible.Basic.AnsibleModule]::Create($args, $spec) | ||
|
||
$path = $module.Params.path | ||
$key = $module.Params.key | ||
$name = $module.Params.name | ||
$data = $module.Params.data | ||
$type = $module.Params.type | ||
$state = $module.Params.state | ||
|
||
$module.Result.reboot_required = $false | ||
|
||
if (-not (Get-Command -Name Get-PolicyFileEntry -ErrorAction SilentlyContinue)) { | ||
$module.FailJson("This version of Windows does not support the Get-PolicyFileEditor.") | ||
} | ||
|
||
try { | ||
$policy_state = Get-PolicyFileEntry -Path $path -Key $key -ValueName $Name | ||
} | ||
catch [System.Runtime.InteropServices.COMException] { | ||
$policy_state = $null | ||
} | ||
|
||
if ($state -eq "present" -and ($policy_state).data -notlike $data) { | ||
if (-not $module.CheckMode) { | ||
Set-PolicyFileEntry -Path $path -Key $key -ValueName $name -Data $data -Type $type | ||
} | ||
$module.Result.changed = $true | ||
} | ||
elseif ($state -eq "absent") { | ||
if (-not $module.CheckMode) { | ||
Remove-PolicyFileEntry -Path $path -Key $key -ValueName $name | ||
} | ||
$module.Result.changed = $true | ||
} | ||
|
||
$module.ExitJson() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters