mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
win_secedit: Added module with tests/diff mode (#26332)
* win_secedit: Added module with tests/diff mode * fixed up test issues * Added missing return value * change for win_secedit based on review * updated win_security_policy examples for rename
This commit is contained in:
parent
53295b2cbf
commit
8e05d7d962
6 changed files with 561 additions and 0 deletions
|
@ -0,0 +1,53 @@
|
|||
#!powershell
|
||||
|
||||
# WANT_JSON
|
||||
# POWERSHELL_COMMON
|
||||
|
||||
# basic script to get the lsit of users in a particular right
|
||||
# this is quite complex to put as a simple script so this is
|
||||
# just a simple module
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
$params = Parse-Args $args -supports_check_mode $false
|
||||
$section = Get-AnsibleParam -obj $params -name "section" -type "str" -failifempty $true
|
||||
$key = Get-AnsibleParam -obj $params -name "key" -type "str" -failifempty $true
|
||||
|
||||
$result = @{
|
||||
changed = $false
|
||||
}
|
||||
|
||||
Function ConvertFrom-Ini($file_path) {
|
||||
$ini = @{}
|
||||
switch -Regex -File $file_path {
|
||||
"^\[(.+)\]" {
|
||||
$section = $matches[1]
|
||||
$ini.$section = @{}
|
||||
}
|
||||
"(.+?)\s*=(.*)" {
|
||||
$name = $matches[1].Trim()
|
||||
$value = $matches[2].Trim()
|
||||
if ($value -match "^\d+$") {
|
||||
$value = [int]$value
|
||||
} elseif ($value.StartsWith('"') -and $value.EndsWith('"')) {
|
||||
$value = $value.Substring(1, $value.Length - 2)
|
||||
}
|
||||
|
||||
$ini.$section.$name = $value
|
||||
}
|
||||
}
|
||||
|
||||
$ini
|
||||
}
|
||||
|
||||
$secedit_ini_path = [IO.Path]::GetTempFileName()
|
||||
&SecEdit.exe /export /cfg $secedit_ini_path /quiet
|
||||
$secedit_ini = ConvertFrom-Ini -file_path $secedit_ini_path
|
||||
|
||||
if ($secedit_ini.ContainsKey($section)) {
|
||||
$result.value = $secedit_ini.$section.$key
|
||||
} else {
|
||||
$result.value = $null
|
||||
}
|
||||
|
||||
Exit-Json $result
|
Loading…
Add table
Add a link
Reference in a new issue