mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 20:01:25 -07:00
* Windows: Add special parameter types Adding explicit parameter types now exposes this information in the module documentation, and proves really helpful. We only do this for non-string types as strings, mostly because strings are implicit. PS We also make copyright statements consistent and use #Requires for explicit library imports * Type "string" must be type "str" * A few more Copyright corrections * More fixes * Don't add file encoding to Powershell files * Don't add missing interfacetypes parameter Otherwise CI demands an incorrect version_added * Small fix
31 lines
948 B
PowerShell
31 lines
948 B
PowerShell
#!powershell
|
|
|
|
# Copyright: (c) 2018, Ripon Banik (@riponbanik)
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
#Requires -Module Ansible.ModuleUtils.Legacy
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$params = Parse-Args $args -supports_check_mode $true
|
|
$name = Get-AnsibleParam -obj $params -name "name" -type "str" -failifempty $true
|
|
$check_mode = Get-AnsibleParam -obj $params -name "_ansible_check_mode" -type "bool" -default $false
|
|
|
|
$current_computer_name = $env:ComputerName
|
|
$result = @{
|
|
changed = $false
|
|
old_name = $current_computer_name
|
|
reboot_required = $false
|
|
}
|
|
|
|
if ($name -ne $current_computer_name) {
|
|
Try {
|
|
Rename-Computer -NewName $name -Force -WhatIf:$check_mode
|
|
} Catch {
|
|
Fail-Json -obj $result -message "Failed to rename computer to '$name': $($_.Exception.Message)"
|
|
}
|
|
$result.changed = $true
|
|
$result.reboot_required = $true
|
|
}
|
|
|
|
Exit-Json -obj $result
|