Debian Codegraph @

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

raw
1 #!powershell
2
3 # Copyright: (c) 2020, ライトウェルの人 <[email protected]>
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 #AnsibleRequires -CSharpUtil Ansible.Basic
7
8 $spec = @{
9 options = @{
10 interface = @{ type = 'list'; elements = 'str'; required = $true }
11 state = @{ type = 'str'; choices = 'disabled', 'enabled'; default = 'enabled' }
12 component_id = @{ type = 'list'; elements = 'str'; required = $true }
13 }
14 supports_check_mode = $true
15 }
16 $module = [Ansible.Basic.AnsibleModule]::Create($args, $spec)
17
18 $interface = $module.Params.interface
19 $state = $module.Params.state
20 $component_id = $module.Params.component_id
21 $check_mode = $module.CheckMode
22
23 If ($interface -eq "*") {
24 $interface = Get-NetAdapter | Select-Object -ExpandProperty Name
25 }
26 Else {
27 ForEach ($Interface_name in $interface) {
28 If (@(Get-NetAdapter | Where-Object Name -eq $Interface_name).Count -eq 0) {
29 $module.FailJson("Invalid network adapter name: $Interface_name")
30 }
31 }
32 }
33
34 $state = $state -eq "enabled"
35
36 ForEach ($componentID_name in $component_id) {
37 If (@(Get-NetAdapterBinding | Where-Object ComponentID -eq $componentID_name).Count -eq 0) {
38 $module.FailJson("Invalid componentID: $componentID_name")
39 }
40 }
41
42 $module.Result.changed = $false
43
44 ForEach ($componentID_name in $component_id) {
45 ForEach ($Interface_name in $interface) {
46 $current_state = (Get-NetAdapterBinding | where-object { $_.Name -eq $Interface_name } | where-object { $_.ComponentID -eq $componentID_name }).Enabled
47 #Initialize the check_Idempotency flag for each interface, and for each component_id.
48 $check_Idempotency = $true
49
50 If ($current_state -eq $state) {
51 $check_Idempotency = $false
52 }
53
54 #Even Once $check_Idempotency remains $true, $module.Result.changed turns $true.
55 $module.Result.changed = $module.Result.changed -Or $check_Idempotency
56
57 If ($check_Idempotency) {
58 If ($state -eq "True") {
59 Enable-NetAdapterBinding -Name $Interface_name -ComponentID $componentID_name -WhatIf:$check_mode
60 }
61 Else {
62 Disable-NetAdapterBinding -Name $Interface_name -ComponentID $componentID_name -WhatIf:$check_mode
63 }
64 }
65 }
66 }
67 $module.ExitJson()