Debian Codegraph @

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

raw
1 #!powershell
2
3 # Copyright: (c) 2015, Peter Mounce <[email protected]>
4 # Copyright: (c) 2017, Ansible Project
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 #Requires -Module Ansible.ModuleUtils.Legacy
8 #Requires -Module Ansible.ModuleUtils.CommandUtil
9
10 $ErrorActionPreference = 'Stop'
11
12 $params = Parse-Args $args -supports_check_mode $true
13 $check_mode = Get-AnsibleParam -obj $params -name "_ansible_check_mode" -type "bool" -default $false
14
15 $result = @{
16 changed = $false
17 }
18
19 Function Invoke-Ngen($architecture = "") {
20 $cmd = "$($env:windir)\Microsoft.NET\Framework$($architecture)\v4.0.30319\ngen.exe"
21
22 if (Test-Path -LiteralPath $cmd) {
23 $arguments = "update /force"
24 if ($check_mode) {
25 $ngen_result = @{
26 rc = 0
27 stdout = "check mode output for $cmd $arguments"
28 }
29 }
30 else {
31 try {
32 $ngen_result = Run-Command -command "$cmd $arguments"
33 }
34 catch {
35 Fail-Json -obj $result -message "failed to execute '$cmd $arguments': $($_.Exception.Message)"
36 }
37 }
38 $result."dotnet_ngen$($architecture)_update_exit_code" = $ngen_result.rc
39 $result."dotnet_ngen$($architecture)_update_output" = $ngen_result.stdout
40
41 $arguments = "executeQueuedItems"
42 if ($check_mode) {
43 $executed_queued_items = @{
44 rc = 0
45 stdout = "check mode output for $cmd $arguments"
46 }
47 }
48 else {
49 try {
50 $executed_queued_items = Run-Command -command "$cmd $arguments"
51 }
52 catch {
53 Fail-Json -obj $result -message "failed to execute '$cmd $arguments': $($_.Exception.Message)"
54 }
55 }
56 $result."dotnet_ngen$($architecture)_eqi_exit_code" = $executed_queued_items.rc
57 $result."dotnet_ngen$($architecture)_eqi_output" = $executed_queued_items.stdout
58 $result.changed = $true
59 }
60 }
61
62 Invoke-Ngen
63 Invoke-Ngen -architecture "64"
64
65 Exit-Json -obj $result