Debian Codegraph @

ansible_collections/community/windows/plugins/modules/win_msg.ps1

raw
1 #!powershell
2
3 # Copyright: (c) 2016, Jon Hawkesworth (@jhawkesworth) <[email protected]>
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 #Requires -Module Ansible.ModuleUtils.Legacy
7 #
8 $stopwatch = [system.diagnostics.stopwatch]::startNew()
9
10 $params = Parse-Args $args -supports_check_mode $true
11 $check_mode = Get-AnsibleParam -obj $params -name "_ansible_check_mode" -type "bool" -default $false
12
13 $display_seconds = Get-AnsibleParam -obj $params -name "display_seconds" -type "int" -default "10"
14 $msg = Get-AnsibleParam -obj $params -name "msg" -type "str" -default "Hello world!"
15 $to = Get-AnsibleParam -obj $params -name "to" -type "str" -default "*"
16 $wait = Get-AnsibleParam -obj $params -name "wait" -type "bool" -default $false
17
18 $result = @{
19 changed = $false
20 display_seconds = $display_seconds
21 msg = $msg
22 wait = $wait
23 }
24
25 if ($msg.Length -gt 255) {
26 Fail-Json -obj $result -message "msg length must be less than 256 characters, current length: $($msg.Length)"
27 }
28
29 $msg_args = @($to, "/TIME:$display_seconds")
30
31 if ($wait) {
32 $msg_args += "/W"
33 }
34
35 $msg_args += $msg
36 if (-not $check_mode) {
37 $output = & msg.exe $msg_args 2>&1
38 $result.rc = $LASTEXITCODE
39 }
40
41 $endsend_at = Get-Date | Out-String
42 $stopwatch.Stop()
43
44 $result.changed = $true
45 $result.runtime_seconds = $stopwatch.Elapsed.TotalSeconds
46 $result.sent_localtime = $endsend_at.Trim()
47
48 if ($result.rc -ne 0 ) {
49 Fail-Json -obj $result -message "$output"
50 }
51
52 Exit-Json $result