This repository has been archived by the owner on Sep 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Get-ICXSession.ps1
125 lines (100 loc) · 3.99 KB
/
Get-ICXSession.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
###############################################################################################################
# Language : PowerShell 4.0
# Filename : Get-ICXSession.ps1
# Autor : BornToBeRoot (https://github.com/BornToBeRoot)
# Description : Get a Brocade ICX session
# Repository : https://github.com/BornToBeRoot/PowerShell_BrocadeICX
###############################################################################################################
<#
.SYNOPSIS
Get a Brocade ICX session
.DESCRIPTION
Get one or multiple Brocade ICX sessions based on SessionID or ComputerName.
.EXAMPLE
Get-ICXSession -SessionID 1, 2
SessionID ComputerName AccessMode
--------- ------------ ----------
1 MEGATRON Privileged
2 megatron Config
.EXAMPLE
Get-ICXSession -ComputerName MEGATRON | Select-Object * | Format-Table
SessionID ComputerName AccessMode Session Stream
--------- ------------ ---------- ------- ------
0 megatron Privileged SSH.SshSession Renci.SshNet.ShellStream
1 MEGATRON Privileged SSH.SshSession Renci.SshNet.ShellStream
2 megatron Config SSH.SshSession Renci.SshNet.ShellStream
.EXAMPLE
Get-ICXSession -ComputerName MEGATRON -CaseSensitive
SessionID ComputerName AccessMode
--------- ------------ ----------
1 MEGATRON Privileged
.LINK
https://github.com/BornToBeRoot/PowerShell_BrocadeICX/blob/master/Documentation/Function/Get-ICXSession.README.md
#>
function Get-ICXSession
{
[CmdletBinding(DefaultParameterSetName='__AllParameterSets')]
param(
[Parameter(
ParameterSetName='SessionID',
Position=0,
Mandatory=$true,
HelpMessage='ID of the Brocade ICX session')]
[Int32[]]$SessionID,
[Parameter(
ParameterSetName='ComputerName',
Position=0,
Mandatory=$true,
HelpMessage='ComputerName of the Brocade ICX session')]
[String[]]$ComputerName,
[Parameter(
ParameterSetName='ComputerName',
Position=1,
HelpMessage='ComputerName must match exactly')]
[switch]$CaseSensitive
)
Begin{
}
Process{
# Temporary array to store Brocade ICX sessions - This is necessary to prevent an enumeration error when removing sessions with the pipe
$ICXSessions = @()
# Switch between the different parameter sets
switch($PSCmdlet.ParameterSetName)
{
"SessionID" {
Write-Verbose -Message "Filter Brocade ICX sessions using the ID."
foreach($SessionID2 in $SessionID)
{
foreach($ICXSession in $Global:BrocadeICXSessions)
{
if($ICXSession.SessionID -eq $SessionID2)
{
$ICXSessions += $ICXSession
}
}
}
}
"ComputerName" {
Write-Verbose -Message "Filter Brocade ICX sessions using the ComputerName."
foreach($ComputerName2 in $ComputerName)
{
foreach($ICXSession in $Global:BrocadeICXSessions)
{
if((($CaseSensitive -eq $false) -and ($ICXSession.ComputerName -eq $ComputerName2)) -or ($ICXSession.ComputerName -ceq $ComputerName2))
{
$ICXSessions += $ICXSession
}
}
}
}
default {
Write-Verbose -Message "No Filter used. Return all Brocade ICX sessions."
$ICXSessions += $Global:BrocadeICXSessions
}
}
Write-Verbose -Message "$($ICXSessions.Count) Brocade ICX session(s) found!"
$ICXSessions
}
End{
}
}