From af6d1f4fb115787071d78c4230637e0d076cf7d9 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Thu, 26 Jul 2018 16:15:29 +0200 Subject: [PATCH 1/5] NetworkDevice: Add Get-ArubaCPNetWorkDevice cmdlet --- PowerArubaCP/Public/NetworkDevice.ps1 | 61 +++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 PowerArubaCP/Public/NetworkDevice.ps1 diff --git a/PowerArubaCP/Public/NetworkDevice.ps1 b/PowerArubaCP/Public/NetworkDevice.ps1 new file mode 100644 index 0000000..a38d0b4 --- /dev/null +++ b/PowerArubaCP/Public/NetworkDevice.ps1 @@ -0,0 +1,61 @@ +# +# Copyright 2018, Alexis La Goutte +# +# SPDX-License-Identifier: Apache-2.0 +# + +function Get-ArubaCPNetworkDevice { + + <# + .SYNOPSIS + Get Network Device info on CPPM + + .DESCRIPTION + Get Network Device (Id, Name, IP, ....) + + .EXAMPLE + Get-ArubaCPNetworkDevice + + Get ALL NetworkDevice on the Clearpass + + .EXAMPLE + Get-ArubaSWVlans Aruba + + Get info about vlan named Aruba on the switch + + .EXAMPLE + Get-ArubaSWVlans -id 23 + + Get info about vlan id 23 on the switch + + #> + + [CmdLetBinding(DefaultParameterSetName="Default")] + + Param( + [Parameter (Mandatory=$false, ParameterSetName="id")] + [int]$id, + [Parameter (Mandatory=$false, ParameterSetName="name", Position=1)] + [string]$Name + ) + + Begin { + } + + Process { + + $url = "api/network-device" + + $nad = Invoke-ArubaCPRestMethod -method "GET" -uri $url + + + switch ( $PSCmdlet.ParameterSetName ) { + "name" { $nad._embedded.items | where-object { $_.name -match $name}} + "id" { $nad._embedded.items | where-object { $_.id -eq $id}} + default { $nad._embedded.items } + } + } + + End { + } +} From 63d47019b95d1ea0b2c43648102490bc6559fd85 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Fri, 10 Aug 2018 15:55:30 +0200 Subject: [PATCH 2/5] NetworkDevice: Add Add-ArubaCPNetworkDevice for adding a NAS name, ip_adress, radius_secret and vendor is Mandatory for vendor, there is a long (static) of autorized vendor... but no yet API to get this list... --- PowerArubaCP/Public/NetworkDevice.ps1 | 110 ++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/PowerArubaCP/Public/NetworkDevice.ps1 b/PowerArubaCP/Public/NetworkDevice.ps1 index a38d0b4..942a419 100644 --- a/PowerArubaCP/Public/NetworkDevice.ps1 +++ b/PowerArubaCP/Public/NetworkDevice.ps1 @@ -4,6 +4,116 @@ # SPDX-License-Identifier: Apache-2.0 # +function Add-ArubaCPNetworkDevice { + + <# + .SYNOPSIS + Add a Network Device (NAD) on ClearPass + + .DESCRIPTION + Add a Network Device (NAD) with radius secret, description, coa_capable, radsec.... + + .EXAMPLE + Add-ArubaCPNetworkDevice -name SW1 -ip_address 192.0.2.1 -radius_secret MySecurePassword -vendor Aruba -description "Add by PowerArubaCP" + + Add Network Device SW1 with ip address 192.0.2.1 from vendor Aruba and a description + + .EXAMPLE + Add-ArubaCPNetworkDevice -name SW2 -ip_address 192.0.2.2 -radius_secret MySecurePassword -vendor Aruba -coa_capable -coa_port 5000 + + Add Network Device SW2 with COA Capability on port 5000 + + .EXAMPLE + Add-ArubaCPNetworkDevice -name SW3 -ip_address 192.0.2.3 -radius_secret MySecurePassword -vendor Cisco -tacacs_secret MySecurePassword + + Add Network Device SW3 with a tacacs secret from vendor Cisco + + .EXAMPLE + Add-ArubaCPNetworkDevice -name SW4 -ip_address 192.0.2.4 -radius_secret MySecurePassword -vendor Hewlett-Packard-Enterprise -radsec_enabled + + Add Network Device SW4 with RadSec from vendor HPE + #> + + Param( + [Parameter (Mandatory=$false)] + [int]$id, + [Parameter (Mandatory=$false)] + [string]$description, + [Parameter (Mandatory=$true)] + [string]$name, + [Parameter (Mandatory=$true)] + [ipaddress]$ip_address, + [Parameter (Mandatory=$true)] + [string]$radius_secret, + [Parameter (Mandatory=$false)] + [string]$tacacs_secret, + [Parameter (Mandatory=$true)] + [string]$vendor_name, + [Parameter (Mandatory=$false)] + [switch]$coa_capable, + [Parameter (Mandatory=$false)] + [int]$coa_port, + [Parameter (Mandatory=$false)] + [switch]$radsec_enabled + ) + + Begin { + } + + Process { + + $url = "api/network-device" + + $_nad = new-Object -TypeName PSObject + + if ( $PsBoundParameters.ContainsKey('id') ) { + $_nad | add-member -name "id" -membertype NoteProperty -Value $id + } + + if ( $PsBoundParameters.ContainsKey('description') ) { + $_nad | add-member -name "description" -membertype NoteProperty -Value $description + } + + $_nad | add-member -name "name" -membertype NoteProperty -Value $name + + $_nad | add-member -name "ip_address" -membertype NoteProperty -Value $ip_address.ToString() + + $_nad | add-member -name "radius_secret" -membertype NoteProperty -Value $radius_secret + + if ( $PsBoundParameters.ContainsKey('tacacs_secret') ) { + $_nad | add-member -name "tacacs_secret" -membertype NoteProperty -Value $tacacs_secret + } + + $_nad | add-member -name "vendor_name" -membertype NoteProperty -Value $vendor_name + + if ( $PsBoundParameters.ContainsKey('coa_capable') ) { + if ( $coa_capable ) { + $_nad | add-member -name "coa_capable" -membertype NoteProperty -Value $True + } else { + $_nad | add-member -name "coa_capable" -membertype NoteProperty -Value $false + } + } + + if ( $PsBoundParameters.ContainsKey('coa_port') ) { + $_nad | add-member -name "coa_port" -membertype NoteProperty -Value $coa_port + } + + if ( $PsBoundParameters.ContainsKey('radsec_enabled') ) { + if ( $radsec_enabled ) { + $_nad | add-member -name "radsec_enabled" -membertype NoteProperty -Value $True + } else { + $_nad | add-member -name "radsec_enabled" -membertype NoteProperty -Value $false + } + } + + $nad = invoke-ArubaCPRestMethod -method "POST" -body $_nad -uri $url + $nad + } + + End { + } +} + function Get-ArubaCPNetworkDevice { <# From 64152972840712caaad13b36827c52af52a83f77 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Fri, 10 Aug 2018 16:18:00 +0200 Subject: [PATCH 3/5] NetworkDevice: Add Remove-Network Device You can remove by id or by pipeline nad via Get-ArubaCPNetworkDevice --- PowerArubaCP/Public/NetworkDevice.ps1 | 64 +++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/PowerArubaCP/Public/NetworkDevice.ps1 b/PowerArubaCP/Public/NetworkDevice.ps1 index 942a419..bc0fc44 100644 --- a/PowerArubaCP/Public/NetworkDevice.ps1 +++ b/PowerArubaCP/Public/NetworkDevice.ps1 @@ -169,3 +169,67 @@ function Get-ArubaCPNetworkDevice { End { } } + +function Remove-ArubaCPNetworkDevice { + + <# + .SYNOPSIS + Remove a Network Device (NAD) on ClearPass + + .DESCRIPTION + Remove a Network Device (NAS) on ClearPass + + .EXAMPLE + $nad = Get-ArubaSWVlans -name NAD-PowerArubaCP + PS C:\>$nad | Remove-ArubaCPNetworkDevice + + Remove Network Device named NAD-PowerArubaCP + + .EXAMPLE + Remove-ArubaCPNetworkDevice -id 3001 -noconfirm + + Remove Network Device id 3001 with no confirmation + #> + + Param( + [Parameter (Mandatory=$true, ParameterSetName="id")] + [int]$id, + [Parameter (Mandatory=$true, ValueFromPipeline=$true, Position=1, ParameterSetName="nad")] + #ValidateScript({ Validatenad $_ })] + [psobject]$nad, + [Parameter(Mandatory = $false)] + [switch]$noconfirm + ) + + Begin { + } + + Process { + + #get nad id from nad ps object + if($nad){ + $id = $nad.id + } + + $url = "api/network-device/${id}" + + if ( -not ( $Noconfirm )) { + $message = "Remove Network Device on ClearPass" + $question = "Proceed with removal of Network Device ${id} ?" + $choices = New-Object Collections.ObjectModel.Collection[Management.Automation.Host.ChoiceDescription] + $choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList '&Yes')) + $choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList '&No')) + + $decision = $Host.UI.PromptForChoice($message, $question, $choices, 1) + } + else { $decision = 0 } + if ($decision -eq 0) { + Write-Progress -activity "Remove Network Device" + Invoke-ArubaCPRestMethod -method "DELETE" -uri $url + Write-Progress -activity "Remove Network Device" -completed + } + } + + End { + } +} \ No newline at end of file From 9097e4d3e3d367acb4a5965daefb46bca2fb27e7 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Fri, 1 Mar 2019 19:41:08 +0100 Subject: [PATCH 4/5] NetworkDevice: Fix example Fix some typo on command name on example... --- PowerArubaCP/Public/NetworkDevice.ps1 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/PowerArubaCP/Public/NetworkDevice.ps1 b/PowerArubaCP/Public/NetworkDevice.ps1 index bc0fc44..4da8ce1 100644 --- a/PowerArubaCP/Public/NetworkDevice.ps1 +++ b/PowerArubaCP/Public/NetworkDevice.ps1 @@ -129,14 +129,14 @@ function Get-ArubaCPNetworkDevice { Get ALL NetworkDevice on the Clearpass .EXAMPLE - Get-ArubaSWVlans Aruba + Get-ArubaCPNetworkDevice NAD-PowerArubaCP - Get info about vlan named Aruba on the switch + Get info about NetworkDevice NAD-PowerArubaCP Aruba on the ClearPass .EXAMPLE - Get-ArubaSWVlans -id 23 + Get-ArubaCPNetworkDevice -id 23 - Get info about vlan id 23 on the switch + Get info about NetworkDevice id 23 on the ClearPass #> @@ -180,7 +180,7 @@ function Remove-ArubaCPNetworkDevice { Remove a Network Device (NAS) on ClearPass .EXAMPLE - $nad = Get-ArubaSWVlans -name NAD-PowerArubaCP + $nad = Get-ArubaCPNetworkDevice -name NAD-PowerArubaCP PS C:\>$nad | Remove-ArubaCPNetworkDevice Remove Network Device named NAD-PowerArubaCP From a66bac671dbd5c7cd71eff5f040fe45e809e1872 Mon Sep 17 00:00:00 2001 From: Alexis La Goutte Date: Fri, 1 Mar 2019 19:41:44 +0100 Subject: [PATCH 5/5] NetworkDevice: Fix indent (using Visual Studio Code Formater) --- PowerArubaCP/Public/NetworkDevice.ps1 | 40 ++++++++++++++------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/PowerArubaCP/Public/NetworkDevice.ps1 b/PowerArubaCP/Public/NetworkDevice.ps1 index 4da8ce1..cde1d11 100644 --- a/PowerArubaCP/Public/NetworkDevice.ps1 +++ b/PowerArubaCP/Public/NetworkDevice.ps1 @@ -35,25 +35,25 @@ function Add-ArubaCPNetworkDevice { #> Param( - [Parameter (Mandatory=$false)] + [Parameter (Mandatory = $false)] [int]$id, - [Parameter (Mandatory=$false)] + [Parameter (Mandatory = $false)] [string]$description, - [Parameter (Mandatory=$true)] + [Parameter (Mandatory = $true)] [string]$name, - [Parameter (Mandatory=$true)] + [Parameter (Mandatory = $true)] [ipaddress]$ip_address, - [Parameter (Mandatory=$true)] + [Parameter (Mandatory = $true)] [string]$radius_secret, - [Parameter (Mandatory=$false)] + [Parameter (Mandatory = $false)] [string]$tacacs_secret, - [Parameter (Mandatory=$true)] + [Parameter (Mandatory = $true)] [string]$vendor_name, - [Parameter (Mandatory=$false)] + [Parameter (Mandatory = $false)] [switch]$coa_capable, - [Parameter (Mandatory=$false)] + [Parameter (Mandatory = $false)] [int]$coa_port, - [Parameter (Mandatory=$false)] + [Parameter (Mandatory = $false)] [switch]$radsec_enabled ) @@ -89,7 +89,8 @@ function Add-ArubaCPNetworkDevice { if ( $PsBoundParameters.ContainsKey('coa_capable') ) { if ( $coa_capable ) { $_nad | add-member -name "coa_capable" -membertype NoteProperty -Value $True - } else { + } + else { $_nad | add-member -name "coa_capable" -membertype NoteProperty -Value $false } } @@ -101,7 +102,8 @@ function Add-ArubaCPNetworkDevice { if ( $PsBoundParameters.ContainsKey('radsec_enabled') ) { if ( $radsec_enabled ) { $_nad | add-member -name "radsec_enabled" -membertype NoteProperty -Value $True - } else { + } + else { $_nad | add-member -name "radsec_enabled" -membertype NoteProperty -Value $false } } @@ -140,12 +142,12 @@ function Get-ArubaCPNetworkDevice { #> - [CmdLetBinding(DefaultParameterSetName="Default")] + [CmdLetBinding(DefaultParameterSetName = "Default")] Param( - [Parameter (Mandatory=$false, ParameterSetName="id")] + [Parameter (Mandatory = $false, ParameterSetName = "id")] [int]$id, - [Parameter (Mandatory=$false, ParameterSetName="name", Position=1)] + [Parameter (Mandatory = $false, ParameterSetName = "name", Position = 1)] [string]$Name ) @@ -192,9 +194,9 @@ function Remove-ArubaCPNetworkDevice { #> Param( - [Parameter (Mandatory=$true, ParameterSetName="id")] + [Parameter (Mandatory = $true, ParameterSetName = "id")] [int]$id, - [Parameter (Mandatory=$true, ValueFromPipeline=$true, Position=1, ParameterSetName="nad")] + [Parameter (Mandatory = $true, ValueFromPipeline = $true, Position = 1, ParameterSetName = "nad")] #ValidateScript({ Validatenad $_ })] [psobject]$nad, [Parameter(Mandatory = $false)] @@ -207,14 +209,14 @@ function Remove-ArubaCPNetworkDevice { Process { #get nad id from nad ps object - if($nad){ + if ($nad) { $id = $nad.id } $url = "api/network-device/${id}" if ( -not ( $Noconfirm )) { - $message = "Remove Network Device on ClearPass" + $message = "Remove Network Device on ClearPass" $question = "Proceed with removal of Network Device ${id} ?" $choices = New-Object Collections.ObjectModel.Collection[Management.Automation.Host.ChoiceDescription] $choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList '&Yes'))