win_region: Small changes to Add-AnsibleParam and docs (#22310)
This commit is contained in:
parent
f1d8d7ba13
commit
770ab76ed0
2 changed files with 12 additions and 45 deletions
|
@ -18,16 +18,15 @@
|
||||||
# POWERSHELL_COMMON
|
# POWERSHELL_COMMON
|
||||||
|
|
||||||
$params = Parse-Args -arguments $args -supports_check_mode $true
|
$params = Parse-Args -arguments $args -supports_check_mode $true
|
||||||
$check_mode = Get-AnsibleParam -obj $params "_ansible_check_mode" -type "bool" -default $false
|
$check_mode = Get-AnsibleParam -obj $params "_ansible_check_mode" -type 'bool' -default $false
|
||||||
|
|
||||||
$location = Get-AnsibleParam -obj $params -name 'location' -failifempty $false -default $null
|
$location = Get-AnsibleParam -obj $params -name 'location' -type 'str'
|
||||||
$format = Get-AnsibleParam -obj $params -name 'format' -failifempty $false -default $null
|
$format = Get-AnsibleParam -obj $params -name 'format' -type 'str'
|
||||||
$unicode_language = Get-AnsibleParam -obj $params -name 'unicode_language' -failifempty $false -default $null
|
$unicode_language = Get-AnsibleParam -obj $params -name 'unicode_language' -type 'str'
|
||||||
$copy_settings = Get-AnsibleParam -obj $params -name 'copy_settings' -type "bool" -failifempty $false -default $false
|
$copy_settings = Get-AnsibleParam -obj $params -name 'copy_settings' -type 'bool' -default $false
|
||||||
|
|
||||||
$result = @{
|
$result = @{
|
||||||
changed = $false
|
changed = $false
|
||||||
warnings = @()
|
|
||||||
restart_required = $false
|
restart_required = $false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,11 +82,7 @@ Function Test-RegistryProperty($reg_key, $property) {
|
||||||
|
|
||||||
Function Copy-RegistryKey($source, $target) {
|
Function Copy-RegistryKey($source, $target) {
|
||||||
# Using Copy-Item -Recurse is giving me weird results, doing it recursively
|
# Using Copy-Item -Recurse is giving me weird results, doing it recursively
|
||||||
if ($check_mode) {
|
Copy-Item -Path $source -Destination $target -WhatIf:$check_mode
|
||||||
Copy-Item -Path $source -Destination $target -WhatIf
|
|
||||||
} else {
|
|
||||||
Copy-Item -Path $source -Destination $target
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($key in Get-ChildItem $source) {
|
foreach($key in Get-ChildItem $source) {
|
||||||
$sourceKey = "$source\$($key.PSChildName)"
|
$sourceKey = "$source\$($key.PSChildName)"
|
||||||
|
@ -163,11 +158,7 @@ Function Set-CultureLegacy($culture) {
|
||||||
$new_value = $wanted_values.$name
|
$new_value = $wanted_values.$name
|
||||||
|
|
||||||
if ($new_value -ne $old_value) {
|
if ($new_value -ne $old_value) {
|
||||||
if ($check_mode) {
|
Set-ItemProperty -Path $reg_key -Name $name -Value $new_value -WhatIf:$check_mode
|
||||||
Set-ItemProperty -Path $reg_key -Name $name -Value $new_value -WhatIf
|
|
||||||
} else {
|
|
||||||
Set-ItemProperty -Path $reg_key -Name $name -Value $new_value
|
|
||||||
}
|
|
||||||
$result.changed = $true
|
$result.changed = $true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,11 +170,7 @@ Function Set-SystemLocaleLegacy($unicode_language) {
|
||||||
$current_language_value = (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Language').Default
|
$current_language_value = (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Language').Default
|
||||||
$wanted_language_value = '{0:x4}' -f ([System.Globalization.CultureInfo]$unicode_language).LCID
|
$wanted_language_value = '{0:x4}' -f ([System.Globalization.CultureInfo]$unicode_language).LCID
|
||||||
if ($current_language_value -ne $wanted_language_value) {
|
if ($current_language_value -ne $wanted_language_value) {
|
||||||
if ($check_mode) {
|
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Language' -Name 'Default' -Value $wanted_language_value -WhatIf:$check_mode
|
||||||
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Language' -Name 'Default' -Value $wanted_language_value -WhatIf
|
|
||||||
} else {
|
|
||||||
Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Nls\Language' -Name 'Default' -Value $wanted_language_value
|
|
||||||
}
|
|
||||||
$result.changed = $true
|
$result.changed = $true
|
||||||
$result.restart_required = $true
|
$result.restart_required = $true
|
||||||
}
|
}
|
||||||
|
@ -216,29 +203,17 @@ Function Set-SystemLocaleLegacy($unicode_language) {
|
||||||
$wanted_mac_cp = $wanted_codepage_info.MacCodePage
|
$wanted_mac_cp = $wanted_codepage_info.MacCodePage
|
||||||
|
|
||||||
if ($current_a_cp -ne $wanted_a_cp) {
|
if ($current_a_cp -ne $wanted_a_cp) {
|
||||||
if ($check_mode) {
|
Set-ItemProperty -Path $codepage_path -Name 'ACP' -Value $wanted_a_cp -WhatIf:$check_mode
|
||||||
Set-ItemProperty -Path $codepage_path -Name 'ACP' -Value $wanted_a_cp -WhatIf
|
|
||||||
} else {
|
|
||||||
Set-ItemProperty -Path $codepage_path -Name 'ACP' -Value $wanted_a_cp
|
|
||||||
}
|
|
||||||
$result.changed = $true
|
$result.changed = $true
|
||||||
$result.restart_required = $true
|
$result.restart_required = $true
|
||||||
}
|
}
|
||||||
if ($current_oem_cp -ne $wanted_oem_cp) {
|
if ($current_oem_cp -ne $wanted_oem_cp) {
|
||||||
if ($check_mode) {
|
Set-ItemProperty -Path $codepage_path -Name 'OEMCP' -Value $wanted_oem_cp -WhatIf:$check_mode
|
||||||
Set-ItemProperty -Path $codepage_path -Name 'OEMCP' -Value $wanted_oem_cp -WhatIf
|
|
||||||
} else {
|
|
||||||
Set-ItemProperty -Path $codepage_path -Name 'OEMCP' -Value $wanted_oem_cp
|
|
||||||
}
|
|
||||||
$result.changed = $true
|
$result.changed = $true
|
||||||
$result.restart_required = $true
|
$result.restart_required = $true
|
||||||
}
|
}
|
||||||
if ($current_mac_cp -ne $wanted_mac_cp) {
|
if ($current_mac_cp -ne $wanted_mac_cp) {
|
||||||
if ($check_mode) {
|
Set-ItemProperty -Path $codepage_path -Name 'MACCP' -Value $wanted_mac_cp -WhatIf:$check_mode
|
||||||
Set-ItemProperty -Path $codepage_path -Name 'MACCP' -Value $wanted_mac_cp -WhatIf
|
|
||||||
} else {
|
|
||||||
Set-ItemProperty -Path $codepage_path -Name 'MACCP' -Value $wanted_mac_cp
|
|
||||||
}
|
|
||||||
$result.changed = $true
|
$result.changed = $true
|
||||||
$result.restart_required = $true
|
$result.restart_required = $true
|
||||||
}
|
}
|
||||||
|
@ -283,11 +258,7 @@ if ($location -ne $null) {
|
||||||
} else {
|
} else {
|
||||||
$current_location = (Get-ItemProperty -Path 'HKCU:\Control Panel\International\Geo').Nation
|
$current_location = (Get-ItemProperty -Path 'HKCU:\Control Panel\International\Geo').Nation
|
||||||
if ($current_location -ne $location) {
|
if ($current_location -ne $location) {
|
||||||
if ($check_mode) {
|
Set-ItemProperty -Path 'HKCU:\Control Panel\International\Geo' -Name 'Nation' -Value $location -WhatIf:$check_mode
|
||||||
Set-ItemProperty -Path 'HKCU:\Control Panel\International\Geo' -Name 'Nation' -Value $location -WhatIf
|
|
||||||
} else {
|
|
||||||
Set-ItemProperty -Path 'HKCU:\Control Panel\International\Geo' -Name 'Nation' -Value $location
|
|
||||||
}
|
|
||||||
$result.changed = $true
|
$result.changed = $true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,14 +40,12 @@ options:
|
||||||
for a list of GeoIDs you can use and what location it relates to.
|
for a list of GeoIDs you can use and what location it relates to.
|
||||||
This needs to be set if C(format) or C(unicode_language) is not
|
This needs to be set if C(format) or C(unicode_language) is not
|
||||||
set.
|
set.
|
||||||
required: false
|
|
||||||
format:
|
format:
|
||||||
description:
|
description:
|
||||||
- The language format to set for the current user, see
|
- The language format to set for the current user, see
|
||||||
U(https://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx)
|
U(https://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.aspx)
|
||||||
for a list of culture names to use. This needs to be set if
|
for a list of culture names to use. This needs to be set if
|
||||||
C(location) or C(unicode_language) is not set.
|
C(location) or C(unicode_language) is not set.
|
||||||
required: false
|
|
||||||
unicode_language:
|
unicode_language:
|
||||||
description:
|
description:
|
||||||
- The unicode language format to set for all users, see
|
- The unicode language format to set for all users, see
|
||||||
|
@ -55,7 +53,6 @@ options:
|
||||||
for a list of culture names to use. This needs to be set if
|
for a list of culture names to use. This needs to be set if
|
||||||
C(location) or C(format) is not set. After setting this
|
C(location) or C(format) is not set. After setting this
|
||||||
value a reboot is required for it to take effect.
|
value a reboot is required for it to take effect.
|
||||||
required: false
|
|
||||||
copy_settings:
|
copy_settings:
|
||||||
description:
|
description:
|
||||||
- This will copy the current format and location values to new user
|
- This will copy the current format and location values to new user
|
||||||
|
@ -63,7 +60,6 @@ options:
|
||||||
C(location), C(format) or C(unicode_language) has resulted in a
|
C(location), C(format) or C(unicode_language) has resulted in a
|
||||||
change. If this process runs then it will always result in a
|
change. If this process runs then it will always result in a
|
||||||
change.
|
change.
|
||||||
required: false
|
|
||||||
default: false
|
default: false
|
||||||
choices: ['true', 'false']
|
choices: ['true', 'false']
|
||||||
author: "Jordan Borean (@jborean93)"
|
author: "Jordan Borean (@jborean93)"
|
||||||
|
|
Loading…
Reference in a new issue