1 #!powershell
2 
3 # Copyright: (c) 2015, Peter Mounce <public@neverrunwithscissors.com>
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 
Invoke-Ngen($architecture="")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         } else {
30             try {
31                 $ngen_result = Run-Command -command "$cmd $arguments"
32             } catch {
33                 Fail-Json -obj $result -message "failed to execute '$cmd $arguments': $($_.Exception.Message)"
34             }
35         }
36         $result."dotnet_ngen$($architecture)_update_exit_code" = $ngen_result.rc
37         $result."dotnet_ngen$($architecture)_update_output" = $ngen_result.stdout
38 
39         $arguments = "executeQueuedItems"
40         if ($check_mode) {
41             $executed_queued_items = @{
42                 rc = 0
43                 stdout = "check mode output for $cmd $arguments"
44             }
45         } else {
46             try {
47                 $executed_queued_items = Run-Command -command "$cmd $arguments"
48             } catch {
49                 Fail-Json -obj $result -message "failed to execute '$cmd $arguments': $($_.Exception.Message)"
50             }
51         }
52         $result."dotnet_ngen$($architecture)_eqi_exit_code" = $executed_queued_items.rc
53         $result."dotnet_ngen$($architecture)_eqi_output" = $executed_queued_items.stdout
54         $result.changed = $true
55     }
56 }
57 
58 Invoke-Ngen
59 Invoke-Ngen -architecture "64"
60 
61 Exit-Json -obj $result
62