Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to get aaasession #105

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NetScaler/NetScaler.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ FunctionsToExport = @(
'Enable-NSMode',
'Get-NSAAAGroup',
'Get-NSAAAGroupBinding',
'Get-NSAAASession'
'Get-NSAAAUser',
'Get-NSAAAUserBinding',
'Get-NSAAAVirtualServer',
Expand Down
96 changes: 96 additions & 0 deletions NetScaler/Public/Get-NSAAASession.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<#
Copyright 2020 Nicolas Rogier

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#>

function Get-NSAAASession {
<#
.SYNOPSIS
Gets NetScaler AAA session(s).

.DESCRIPTION
Gets NetScaler AAA session(s). If no parameters are provided all AAA
sessions are returned. The 'Username' and 'Filter' parameters can be
used to select a specific session or a subset of sessions.

.EXAMPLE
Get-NSAAASession

Gets all AAA users.

.EXAMPLE
Get-NSAAASession -Username 'User1','User2','User3'

Gets AAA sessions for User1, User2, and User3.

.EXAMPLE
Get-NSAAASession -Filter 'ABC'

Gets all AAA sessions with 'ABC' in the username.

.PARAMETER Name
Defines the specific AAA session(s) to be returned.

.PARAMETER Filter
When specified, only sessions that username contain the
provided string are returned.

.PARAMETER Session
The NetScaler session object.
#>

[cmdletbinding()]
param(
[Parameter(
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true,
Position = 0)]
[alias('UserName')]
[string[]]$Name,
[string]$Filter,

$Session = $script:session
)

begin {
_AssertSessionActive
}

process {
Try {
$response = _InvokeNSRestApi -Session $Session -Method Get -Type aaasession -Action Get
if ($response.psobject.properties | Where-Object { $_.name -eq 'aaasession' }) {
if (-Not([string]::IsNullOrEmpty($Name))) {
foreach ($User in $Name) {
if ($response.aaasession | Where-Object { $_.username -eq $User }) {
$response.aaasession | Where-Object { $_.username -eq $User }
}
}
} else {
if (-Not([string]::IsNullOrEmpty($Filter))) {
foreach ($item in $response.aaasession) {
if ($item.username -match "$Filter") {
$item
}
}
} else {
$response.aaasession
}
}
}
} Catch {
Throw $_
}
}
}