-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-HPOVInterconnectPorts.ps1
130 lines (113 loc) · 4.77 KB
/
Get-HPOVInterconnectPorts.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
<#
.SYNOPSIS
Gets Interconnect uplink port information from OneView.
.DESCRIPTION
Gets the uplink port information for one or more interconnects in OneView. Only FlexFabric interconnects
(not FiberChannel) and Ethernet ports are retrieved. The corresponding uplink set from the Logical
Interconnect Group is also retrieved for each port and the VLANs that should be configured are listed.
.PARAMETER Appliance
Name of the OneView appliance. This parameter is optional if there is already a connected session in
$global:ConnectedSessions.
.PARAMETER Enclosure
Optional name of an enclosure to get interconnects for. If omitted all interconnects for all enclosures
are retrieved.
.PARAMETER Interconnect
Optional name of a specific interconnect to retrieve info for. The name should match the one shown in
OneView.
.EXAMPLE
Get info for all interconnects in a OneView appliance:
Get-HPOVInterconnectPorts.ps1 -Appliance oneview.mydomain.local
.EXAMPLE
Get info for a single interconnect:
Get-HPOVInterconnectPorts.ps1 -Interconnect 'MyEnclosure, interconnect 1' -Appliance oneview.mydomain.local
.EXAMPLE
Get info for all interconnects in an enclosure:
Get-HPOVInterconnectPorts.ps1 -Enclosure 'MyEnclosure'
.NOTES
Requires HPOneView module
.LINK
https://hewlettpackard.github.io/POSH-HPOneView/
.LINK
https://github.com/doogleit/hpe-oneview-misc
#>
[CmdletBinding()]
param (
[Parameter(Mandatory=$false,ValueFromPipeline=$true)]
[string]$Appliance,
[string]$Enclosure,
[string]$Interconnect
)
Begin {
If ($Appliance) {
Try {
$ovw = Connect-HPOVMgmt -Appliance $Appliance
}
Catch {
Throw "OneView appliance connection failed."
}
}
ElseIf ($global:ConnectedSessions.Count -eq 1) {
# use existing session
$ovw = $global:ConnectedSessions[0]
Write-Host "Using existing connection: $($ovw.Name)"
}
Else {
Write-Warning "You must specify an appliance name using '-Appliance' or already be connected using Connect-HPOVMgmt."
Throw "No OneView appliance connection."
}
$results = @() # array containing the results
}
Process {
$ovwInterconnects = @()
If ($Interconnect) {
Write-Host "Getting interconnect: $Interconnect"
$ovwInterconnects += Get-HPOVInterconnect -Name $Interconnect -ApplianceConnection $ovw
$output = "UplinkInfo-$Interconnect-$(Get-Date -format 'yyyy.MM.dd.HHmm').csv"
}
ElseIf ($Enclosure) {
Write-Host "Getting interconnects for enclosure: $Enclosure"
$ovwEncl = Get-HPOVEnclosure -ApplianceConnection $ovw -Name $Enclosure
ForEach ($bay in $ovwEncl.interconnectBays) {
If ($bay.interconnectModel -Match 'FlexFabric') {
$ovwInterconnects += (Send-HPOVRequest -Uri $bay.interconnectUri -Hostname $ovw.Name)
}
}
$output = "UplinkInfo-$Enclosure-$(Get-Date -format 'yyyy.MM.dd.HHmm').csv"
}
Else {
Write-Host "Getting interconnects from appliance: $($ovw.Name)"
$ovwInterconnects += Get-HPOVInterconnect -ApplianceConnection $ovw | where 'Model' -match 'FlexFabric'
$output = "UplinkInfo-$($ovw.Name)-$(Get-Date -format 'yyyy.MM.dd.HHmm').csv"
}
Write-Host "Number of interconnects retrieved: $($ovwInterconnects.Count)"
ForEach ($ovwInterconnect in $ovwInterconnects) {
Write-Host "Getting ports for $($ovwInterconnect.Name)"
$ports = $ovwInterconnect.ports | where 'portType' -eq 'Uplink' | where 'portStatus' -eq 'Linked' `
| where 'capability' -contains 'Ethernet'
ForEach ($port in $ports) {
$uplinkSet = Send-HPOVRequest -Uri $port.associatedUplinkSetUri -Hostname $ovw.Name
$networkUris = $uplinkSet.networkUris
$vlans = @()
ForEach ($netUri in $networkUris) {
$vlans += (Send-HPOVRequest $netUri -Hostname $ovw.Name).vlanId
}
$portInfo = New-Object -TypeName PSObject -Prop ([ordered]@{
'Interconnect Name' = $ovwInterconnect.Name;
'Interconnect Port' = $port.portName;
'Switch Port' = $port.neighbor.remotePortId;
'Port Description' = $port.neighbor.remotePortDescription;
'Address Type' = $port.neighbor.remoteMgmtAddressType;
'Switch Address' = $port.neighbor.remoteMgmtAddress;
'Switch Name' = $port.neighbor.remoteSystemName
'Vlans' = ($vlans -join ', ')
})
$results += $portInfo
}
}
} # end process block
End {
# Save results to CSV
$results | Export-Csv -Path $output -NoTypeInformation
# Write results to the console
$results | Format-Table -AutoSize
}