Public/Poe.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#
# Copyright 2018, Alexis La Goutte <alexis dot lagoutte at gmail dot com>
#
# SPDX-License-Identifier: Apache-2.0
#


function Get-ArubaSWPoE {

    <#
        .SYNOPSIS
        Get PoE info about ArubaOS Switch (Provision)
 
        .DESCRIPTION
        Get PoE Info (Status, Priority, Allocation...)
 
        .EXAMPLE
        Get-ArubaSWPoE
 
        Get ALL PoE Settings on the switch
 
        .EXAMPLE
        Get-ArubaSWPoE -port 3
 
        Get PoE settings on port 3
    #>

    Param(
        [Parameter (Mandatory = $false, position = 1)]
        [string]$port_id
    )

    Begin {
    }

    Process {

        $uri = "rest/v4/poe/ports"

        if ( $port_id ) {
            $uri = "rest/v4/ports/$port_id/poe"
        }

        $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri

        $poe = ($response.Content | ConvertFrom-Json)

        if ( $port_id ) {
            $poe
        }
        else {
            $poe.port_poe
        }
    }

    End {
    }
}
function Set-ArubaSWPoE {

    <#
        .SYNOPSIS
        Configure PoE Settings on ArubaOS Switch (Provision)
 
        .DESCRIPTION
        Configure PoE Settings (Status, Priority, Allocation...)
 
        .EXAMPLE
        $port_poe = Get-ArubaSWPoE -port 3
        PS C:\>$port_poe | Set-ArubaSWPoE -is_poe_enabled:$false -poe_priority high -poe_allocation_method class
 
        Configure port 3 and disable PoE with priority high and allocation method class
 
        .EXAMPLE
        Set-ArubaSWPoE -port_id 3 -poe_allocation_method value -allocated_power_in_watts 33 -pre_standard_detect_enabled:$false
 
        Configure port 3 and set allocated method and allocated power to 33 (Watts) and disable pre_standard_detect
 
    #>


    Param(
        [Parameter (Mandatory = $true, ParameterSetName = "port_id")]
        [string]$port_id,
        [Parameter (Mandatory = $true, ValueFromPipeline = $true, Position = 1, ParameterSetName = "port_poe")]
        #ValidateScript({ ValidatePoE $_ })]
        [psobject]$port_poe,
        [Parameter (Mandatory = $false)]
        [switch]$is_poe_enabled,
        [Parameter (Mandatory = $false)]
        [ValidateSet ("low", "high", "critical")]
        [string]$poe_priority,
        [Parameter (Mandatory = $false)]
        [ValidateSet ("usage", "class", "value")]
        [string]$poe_allocation_method,
        [Parameter (Mandatory = $false)]
        [ValidateRange (1, 33)]
        [int]$allocated_power_in_watts,
        [Parameter (Mandatory = $false)]
        [string]$port_configured_type,
        [Parameter (Mandatory = $false)]
        [switch]$pre_standard_detect_enabled
    )

    Begin {
    }

    Process {

        #get port id from poe ps object
        if ($port_poe) {
            $port_id = $port_poe.port_id
        }
        $uri = "rest/v4/ports/${port_id}/poe"

        $_poe = New-Object -TypeName PSObject


        if ( $PsBoundParameters.ContainsKey('is_poe_enabled') ) {
            if ( $is_poe_enabled ) {
                $_poe | Add-Member -name "is_poe_enabled" -membertype NoteProperty -Value $true
            }
            else {
                $_poe | Add-Member -name "is_poe_enabled" -membertype NoteProperty -Value $false
            }
        }

        if ( $PsBoundParameters.ContainsKey('poe_priority') ) {
            switch ( $poe_priority ) {
                low {
                    $priority = "PPP_LOW"
                }
                high {
                    $priority = "PPP_HIGH"
                }
                critical {
                    $priority = "PPP_CRITICAL"
                }
            }
            $_poe | Add-Member -name "poe_priority" -membertype NoteProperty -Value $priority
        }

        if ( $PsBoundParameters.ContainsKey('poe_allocation_method') ) {
            switch ( $poe_allocation_method ) {
                usage {
                    $allocation_method = "PPAM_USAGE"
                }
                class {
                    $allocation_method = "PPAM_CLASS"
                }
                value {
                    $allocation_method = "PPAM_VALUE"
                }
            }
            $_poe | Add-Member -name "poe_allocation_method" -membertype NoteProperty -Value $allocation_method
        }

        if ( $PsBoundParameters.ContainsKey('allocated_power_in_watts') ) {
            $_poe | Add-Member -name "allocated_power_in_watts" -membertype NoteProperty -Value $allocated_power_in_watts
        }

        if ( $PsBoundParameters.ContainsKey('port_configured_type') ) {
            $_poe | Add-Member -name "port_configured_type" -membertype NoteProperty -Value $port_configured_type
        }

        if ( $PsBoundParameters.ContainsKey('pre_standard_detect_enabled') ) {
            if ( $pre_standard_detect_enabled ) {
                $_poe | Add-Member -name "pre_standard_detect_enabled" -membertype NoteProperty -Value $true
            }
            else {
                $_poe | Add-Member -name "pre_standard_detect_enabled" -membertype NoteProperty -Value $false
            }
        }

        $response = Invoke-ArubaSWWebRequest -method "PUT" -body $_poe -uri $uri
        $rep_poe = ($response.Content | ConvertFrom-Json)

        $rep_poe
    }

    End {
    }
}

function Get-ArubaSWPoEStats {

    <#
        .SYNOPSIS
        Get PoE statistics about ArubaOS Switch (Provision)
 
        .DESCRIPTION
        Get PoE statistics (Voltage, Class ...)
 
        .EXAMPLE
        Get-ArubaSWPoEStats
 
        Get ALL PoE ports statistics on the switch
 
        .EXAMPLE
        Get-ArubaSWPoEstats -port 3
 
        Get PoE statistics on port 3
    #>

    Param(
        [Parameter (Mandatory = $false, position = 1)]
        [string]$port_id
    )

    Begin {
    }

    Process {

        $uri = "rest/v4/poe/ports/stats"

        if ( $port_id ) {
            $uri = "rest/v4/ports/$port_id/poe/stats"
        }

        $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri

        $poe = ($response.Content | ConvertFrom-Json)

        if ( $port_id ) {
            $poe
        }
        else {
            $poe.port_poe_stats
        }
    }

    End {
    }
}