├── AuvikAPI ├── AuvikAPI.psm1 ├── Internal │ ├── BaseURI.ps1 │ ├── APICredential.ps1 │ └── ModuleSettings.ps1 ├── Resources │ ├── MetaData.ps1 │ ├── Authentication.ps1 │ ├── Component.ps1 │ ├── Configuration.ps1 │ ├── Interface.ps1 │ ├── AlertHistory.ps1 │ ├── Tenants.ps1 │ ├── Entity.ps1 │ ├── Network.ps1 │ ├── Billing.ps1 │ └── Device.ps1 └── AuvikAPI.psd1 ├── README.md └── LICENSE /AuvikAPI/AuvikAPI.psm1: -------------------------------------------------------------------------------- 1 | $AuvikAPI_Headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" 2 | $AuvikAPI_Headers.Add("Content-Type", 'application/vnd.api+json') 3 | 4 | Set-Variable -Name "AuvikAPI_Headers" -Value $AuvikAPI_Headers -Scope global 5 | 6 | 7 | Import-AuvikModuleSettings -------------------------------------------------------------------------------- /AuvikAPI/Internal/BaseURI.ps1: -------------------------------------------------------------------------------- 1 | function Add-AuvikBaseURI { 2 | [CmdletBinding(DefaultParameterSetName = 'uri')] 3 | Param ( 4 | [parameter(ParameterSetName = 'uri',ValueFromPipeline,Position=1)] 5 | [string]$BaseURI = 'https://auvikapi.us1.my.auvik.com', 6 | 7 | [Parameter(ParameterSetName = 'datacenter')] 8 | [Alias('locale','dc')] 9 | [ValidatePattern("(US|EU)\d?")] 10 | [String]$data_center 11 | ) 12 | 13 | If ($PSCmdlet.ParameterSetName -eq 'uri') { 14 | # Trim superflous forward slash from address (if applicable) 15 | If ($BaseURI[$BaseURI.Length-1] -eq "/") { 16 | $BaseURI = $BaseURI.Substring(0,$BaseURI.Length-1) 17 | } 18 | } ElseIf ($PSCmdlet.ParameterSetName -eq 'datacenter') { 19 | Write-Verbose "Evaluating Datacenter parameter `"$($data_center)`"" 20 | # Assume DataCenter #1 if not specified 21 | switch -regex ($data_center) { 22 | '^US$' {$BaseURI = 'https://auvikapi.us1.my.auvik.com'; Break} 23 | '^EU$' {$BaseURI = 'https://auvikapi.eu1.my.auvik.com'; Break} 24 | Default {$BaseURI = "https://auvikapi.$($data_center.ToLower()).my.auvik.com"} 25 | } 26 | } 27 | Write-Verbose "Assigning Auvik_Base_URI=`"$($BaseURI)`"" 28 | Set-Variable -Name "Auvik_Base_URI" -Value $BaseURI -Option ReadOnly -Scope global -Force 29 | } 30 | 31 | function Remove-AuvikBaseURI { 32 | Remove-Variable -Name "Auvik_Base_URI" -Scope global -Force 33 | } 34 | 35 | function Get-AuvikBaseURI { 36 | Return $Auvik_Base_URI 37 | } 38 | 39 | New-Alias -Name Set-AuvikBaseURI -Value Add-AuvikBaseURI -------------------------------------------------------------------------------- /AuvikAPI/Internal/APICredential.ps1: -------------------------------------------------------------------------------- 1 | function Add-AuvikAPICredential { 2 | [cmdletbinding()] 3 | Param ( 4 | [Parameter(Mandatory = $false, ValueFromPipeline = $true)] 5 | [AllowEmptyString()] 6 | [Alias('Email')] 7 | [string]$UserName, 8 | [Parameter(Mandatory = $false, ValueFromPipeline = $true)] 9 | [AllowEmptyString()] 10 | [Alias('ApiKey')] 11 | [string]$Api_Key 12 | ) 13 | 14 | If ($UserName) { 15 | Set-Variable -Name "Auvik_User" -Value $UserName -Option ReadOnly -Scope global -Force 16 | } 17 | Else { 18 | Write-Host "Please enter your Auvik User Email Address:" 19 | $UserName = Read-Host 20 | 21 | Set-Variable -Name "Auvik_User" -Value $UserName -Option ReadOnly -Scope global -Force 22 | } 23 | 24 | If ($Api_Key) { 25 | $x_api_key = ConvertTo-SecureString $Api_Key -AsPlainText -Force 26 | 27 | Set-Variable -Name "Auvik_API_Key" -Value $x_api_key -Option ReadOnly -Scope global -Force 28 | } 29 | Else { 30 | Write-Host "Please enter your API key:" 31 | $x_api_key = Read-Host -AsSecureString 32 | 33 | Set-Variable -Name "Auvik_API_Key" -Value $x_api_key -Option ReadOnly -Scope global -Force 34 | } 35 | 36 | Set-Variable -Name "Auvik_API_Credential" -Value (New-Object System.Management.Automation.PSCredential -ArgumentList $Auvik_User, $Auvik_API_Key) -Option ReadOnly -Scope global -Force 37 | 38 | } 39 | 40 | function Remove-AuvikAPICredential { 41 | Remove-Variable -Name "Auvik_User","Auvik_API_Key","Auvik_API_Credential" -Force 42 | } 43 | 44 | function Get-AuvikAPICredential { 45 | 46 | If ($Auvik_API_Credential -eq $null) { 47 | Write-Error "No API credentials exists. Please run Add-AuvikAPICredential to add one." 48 | } 49 | Else { 50 | $Auvik_API_Credential 51 | } 52 | } 53 | 54 | New-Alias -Name Set-AuvikAPICredential -Value Add-AuvikAPICredential 55 | -------------------------------------------------------------------------------- /AuvikAPI/Resources/MetaData.ps1: -------------------------------------------------------------------------------- 1 | function Get-AuvikMetaField { 2 | [CmdletBinding(DefaultParameterSetName = 'field')] 3 | Param ( 4 | [Parameter(ParameterSetName = 'field',Mandatory=$True)] 5 | [String]$Endpoint, 6 | 7 | [Parameter(ParameterSetName = 'field',Mandatory=$True)] 8 | [String]$Field 9 | 10 | ) 11 | 12 | Begin { 13 | $data = @() 14 | $qparams = @{} 15 | $x_api_authorization = "$($Auvik_API_Credential.UserName):$([Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Auvik_API_Credential.Password)))" 16 | $x_api_authorization = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($x_api_authorization)) 17 | } 18 | 19 | Process { 20 | If ($PSCmdlet.ParameterSetName -eq 'field') { 21 | If ($Endpoint) { 22 | $qparams += @{'endpoint' = $Endpoint} 23 | } 24 | If ($Field) { 25 | $qparams += @{'field' = $Field} 26 | } 27 | } 28 | Else { 29 | } 30 | 31 | $resource_uri = ('/v1/meta/field/info') 32 | 33 | $attempt=0 34 | Do { 35 | $attempt+=1 36 | If ($attempt -gt 1) {Start-Sleep 2} 37 | Write-Debug "Testing $('https://auvikapi.my.auvik.com' + $resource_uri)$(If ($qparams.Count -gt 0) {'?' + $(($qparams.GetEnumerator() | ForEach-Object {"$($_.Name)=$($_.Value)"}) -join '&') })" 38 | $rest_output = try { 39 | $Null = $AuvikAPI_Headers.Add("Authorization", "Basic $x_api_authorization") 40 | Invoke-RestMethod -method 'GET' -uri ($Auvik_Base_URI + $resource_uri) -Headers $AuvikAPI_Headers -Body $qparams -ErrorAction SilentlyContinue 41 | } catch [System.Net.WebException] { 42 | $_.Exception.Response 43 | } catch { 44 | Write-Error $_ 45 | } finally { 46 | $Null = $AuvikAPI_Headers.Remove('Authorization') 47 | } 48 | Write-Verbose "Status Code Returned: $([int]$rest_output.StatusCode)" 49 | } Until ($([int]$rest_output.StatusCode) -ne 502 -or $attempt -ge 5) 50 | $data += $rest_output 51 | } 52 | 53 | End { 54 | Return $data 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /AuvikAPI/Internal/ModuleSettings.ps1: -------------------------------------------------------------------------------- 1 | function Export-AuvikModuleSettings { 2 | 3 | $secureString = $Auvik_API_KEY | ConvertFrom-SecureString 4 | $outputPath = "$($env:USERPROFILE)\AuvikAPI" 5 | New-Item -ItemType Directory -Force -Path $outputPath | ForEach-Object {$_.Attributes = "hidden"} 6 | @" 7 | @{ 8 | Auvik_Base_URI = '$Auvik_Base_URI' 9 | Auvik_User = '$Auvik_User' 10 | Auvik_API_Key = '$secureString' 11 | Auvik_JSON_Conversion_Depth = '$Auvik_JSON_Conversion_Depth' 12 | } 13 | "@ | Out-File -FilePath ($outputPath+"\config.psd1") -Force 14 | 15 | } 16 | 17 | function Import-AuvikModuleSettings { 18 | 19 | # Should Add Error Checking 20 | 21 | If (test-path "$($env:USERPROFILE)\AuvikAPI") { 22 | $tmp_config = Import-LocalizedData -BaseDirectory "$($env:USERPROFILE)\AuvikAPI" -FileName "config.psd1" 23 | 24 | # Send to function to strip potentially superfluous slash (/) 25 | Add-AuvikBaseURI $tmp_config.Auvik_Base_URI 26 | 27 | $tmp_config.Auvik_API_key = ConvertTo-SecureString $tmp_config.Auvik_API_key 28 | 29 | Set-Variable -Name "Auvik_User" -Value $tmp_config.Auvik_User -Option ReadOnly -Scope global -Force 30 | 31 | Set-Variable -Name "Auvik_API_Key" -Value $tmp_config.Auvik_API_key -Option ReadOnly -Scope global -Force 32 | 33 | Set-Variable -Name "Auvik_API_Credential" -Value (New-Object System.Management.Automation.PSCredential -ArgumentList $Auvik_User, $Auvik_API_Key) -Option ReadOnly -Scope global -Force 34 | 35 | Set-Variable -Name "Auvik_JSON_Conversion_Depth" -Value $tmp_config.Auvik_JSON_Conversion_Depth -Scope global -Force 36 | 37 | # Clean things up 38 | Remove-Variable "tmp_config","Auvik_User","Auvik_API_Key" -ErrorAction SilentlyContinue 39 | 40 | Write-Host "Module configuration loaded successfully!" -ForegroundColor Green 41 | } 42 | Else { 43 | Write-Host "No configuration file was found." -ForegroundColor Red 44 | Write-Host "Please run Add-AuvikAPICredential to get started." -ForegroundColor Red 45 | 46 | Add-AuvikBaseURI 47 | Write-Host "Using $(Get-AuvikBaseURI) as Base URI. Run Add-AuvikBaseURI to modify." 48 | 49 | Set-Variable -Name "Auvik_JSON_Conversion_Depth" -Value 100 -Scope global -Force 50 | } 51 | } -------------------------------------------------------------------------------- /AuvikAPI/Resources/Authentication.ps1: -------------------------------------------------------------------------------- 1 | function Confirm-AuvikAPICredential { 2 | [CmdletBinding(DefaultParameterSetName = 'credential')] 3 | Param ( 4 | [Parameter(ParameterSetName = 'userkey')] 5 | [String]$UserName = '', 6 | 7 | [Parameter(ParameterSetName = 'userkey')] 8 | [Alias('APIKey')] 9 | [String]$API_Key = '', 10 | 11 | [Parameter(ParameterSetName = 'credential')] 12 | [PSCredential]$Credential = $Auvik_API_Credential, 13 | 14 | [Parameter(ParameterSetName = 'userkey')] 15 | [Parameter(ParameterSetName = 'credential')] 16 | [Switch]$Quiet 17 | ) 18 | 19 | $x_api_authorization = $Null 20 | $resource_uri = ('/authentication/verify') 21 | 22 | If ($PSCmdlet.ParameterSetName -eq 'userkey') { 23 | If ($Api_Key) { 24 | $x_api_authorization = "$($Username):$($API_Key)" 25 | } 26 | } Else { 27 | $x_api_authorization = "$($Auvik_API_Credential.UserName):$([Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Auvik_API_Credential.Password)))" 28 | } 29 | 30 | $data = @{} 31 | 32 | If ($x_api_authorization) { 33 | Write-Debug "Testing $($Auvik_Base_URI + $resource_uri) with $x_api_authorization" 34 | $x_api_authorization = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($x_api_authorization)) 35 | $attempt=0 36 | Do { 37 | $attempt+=1 38 | If ($attempt -gt 1) {Start-Sleep 2} 39 | $AuvikAPI_Headers.Add("Authorization", "Basic $x_api_authorization") 40 | $rest_output = try { 41 | Invoke-WebRequest -method 'GET' -uri ($Auvik_Base_URI + $resource_uri) -Headers $AuvikAPI_Headers ` 42 | -ErrorAction SilentlyContinue 43 | } catch [System.Net.WebException] { 44 | $_.Exception.Response 45 | } finally { 46 | $Null = $AuvikAPI_Headers.Remove('Authorization') 47 | } 48 | Write-Verbose "Status Code Returned: $([int]$rest_output.StatusCode)" 49 | } Until ($([int]$rest_output.StatusCode) -ne 502 -or $attempt -ge 5) 50 | If ([int]$rest_output.StatusCode -ne 200) { 51 | If (!$Quiet) { 52 | Write-Error "Authorization was not successful. Code Returned: $([int]$rest_output.StatusCode)" 53 | } Else { $rest_output = $False } 54 | } ElseIf ($Quiet) { 55 | $rest_output = $True 56 | } 57 | $data = $rest_output 58 | } Else { 59 | Write-Error "No credentials were provided." 60 | } 61 | 62 | Return $data 63 | } 64 | -------------------------------------------------------------------------------- /AuvikAPI/Resources/Component.ps1: -------------------------------------------------------------------------------- 1 | function Get-AuvikComponentsInfo { 2 | [CmdletBinding(DefaultParameterSetName = 'index')] 3 | Param ( 4 | [Parameter(ParameterSetName = 'show')] 5 | [String[]]$Id, 6 | 7 | [Parameter(ParameterSetName = 'index')] 8 | [String[]]$Devices = '', 9 | 10 | [Parameter(ParameterSetName = 'index')] 11 | [String]$DeviceName = '', 12 | 13 | [Parameter(ParameterSetName = 'index')] 14 | [ValidateSet('ok','degraded','failed')] 15 | [String]$CurrentStatus = '', 16 | 17 | [Parameter(ParameterSetName = 'index')] 18 | [datetime]$ModifiedAfter, 19 | 20 | [Parameter(ParameterSetName = 'index')] 21 | [String[]]$Tenants = '' 22 | 23 | ) 24 | 25 | Begin { 26 | $data = @() 27 | $qparams = @{} 28 | $x_api_authorization = "$($Auvik_API_Credential.UserName):$([Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Auvik_API_Credential.Password)))" 29 | $x_api_authorization = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($x_api_authorization)) 30 | } 31 | 32 | Process { 33 | 34 | If ($PSCmdlet.ParameterSetName -eq 'index') { 35 | $Id = @('') 36 | If ($Tenants) { 37 | $qparams += @{'tenants' = $Tenants -join ','} 38 | } 39 | If ($DeviceName) { 40 | $qparams += @{'filter[deviceName]' = $DeviceName} 41 | } 42 | If ($CurrentStatus) { 43 | $qparams += @{'filter[currentStatus]' = $CurrentStatus} 44 | } 45 | If ($ModifiedAfter) { 46 | $qparams += @{'filter[modifiedAfter]' = $ModifiedAfter.ToString('yyyy-MM-ddTHH:mm:ss.fffzzz')} 47 | } 48 | } 49 | Else { 50 | #Parameter set "Show" is selected 51 | $Devices = @('') 52 | } 53 | 54 | ForEach ($componentId IN $Id) { 55 | ForEach ($DeviceId IN $Devices) { 56 | $resource_uri = ('/v1/inventory/component/info') 57 | If (!($Null -eq $componentId) -and $componentId -gt '') { 58 | $resource_uri = ('/v1/inventory/component/info/{0}' -f $componentId) 59 | } ElseIf (!($Null -eq $DeviceId) -and $DeviceId -gt '') { 60 | $qparams['filter[deviceId]'] = $DeviceId 61 | } Else { 62 | $Null = $qparams.Remove('filter[deviceId]') 63 | } 64 | 65 | $attempt=0 66 | Do { 67 | $attempt+=1 68 | If ($attempt -gt 1) {Start-Sleep 2} 69 | Write-Debug "Testing $($Auvik_Base_URI + $resource_uri)$(If ($qparams.Count -gt 0) {'?' + $(($qparams.GetEnumerator() | ForEach-Object {"$($_.Name)=$($_.Value)"}) -join '&') })" 70 | $rest_output = try { 71 | $Null = $AuvikAPI_Headers.Add("Authorization", "Basic $x_api_authorization") 72 | Invoke-RestMethod -method 'GET' -uri ($Auvik_Base_URI + $resource_uri) -Headers $AuvikAPI_Headers -Body $qparams -ErrorAction SilentlyContinue 73 | } catch [System.Net.WebException] { 74 | $_.Exception.Response 75 | } catch { 76 | Write-Error $_ 77 | } finally { 78 | $Null = $AuvikAPI_Headers.Remove('Authorization') 79 | } 80 | Write-Verbose "Status Code Returned: $([int]$rest_output.StatusCode)" 81 | } Until ($([int]$rest_output.StatusCode) -ne 502 -or $attempt -ge 5) 82 | $data += $rest_output | Where-Object {$_.Data.ID -gt ''} 83 | } 84 | } 85 | } 86 | 87 | End { 88 | Return $data 89 | } 90 | 91 | } 92 | 93 | -------------------------------------------------------------------------------- /AuvikAPI/Resources/Configuration.ps1: -------------------------------------------------------------------------------- 1 | function Get-AuvikDeviceConfiguration { 2 | [CmdletBinding(DefaultParameterSetName = 'index')] 3 | Param ( 4 | [Parameter(ParameterSetName = 'show')] 5 | [String[]]$Id, 6 | 7 | [Parameter(ParameterSetName = 'index')] 8 | [String[]]$Devices = '', 9 | 10 | [Parameter(ParameterSetName = 'index')] 11 | [String[]]$Tenants = '', 12 | 13 | [Parameter(ParameterSetName = 'index')] 14 | [datetime]$BackupTimeAfter, 15 | 16 | [Parameter(ParameterSetName = 'index')] 17 | [datetime]$BackupTimeBefore, 18 | 19 | [Parameter(ParameterSetName = 'index')] 20 | [Nullable[Boolean]]$IsRunning 21 | 22 | ) 23 | 24 | Begin { 25 | $data = @() 26 | $qparams = @{} 27 | $x_api_authorization = "$($Auvik_API_Credential.UserName):$([Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Auvik_API_Credential.Password)))" 28 | $x_api_authorization = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($x_api_authorization)) 29 | } 30 | 31 | Process { 32 | 33 | If ($PSCmdlet.ParameterSetName -eq 'index') { 34 | $Id = @('') 35 | If ($Tenants) { 36 | $qparams += @{'tenants' = $Tenants -join ','} 37 | } 38 | If ($BackupTimeAfter) { 39 | $qparams += @{'filter[backupTimeAfter]' = $BackupTimeAfter.ToString('yyyy-MM-ddTHH:mm:ss.fffzzz')} 40 | } 41 | If ($BackupTimeBefore) { 42 | $qparams += @{'filter[backupTimeBefore]' = $BackupTimeBefore.ToString('yyyy-MM-ddTHH:mm:ss.fffzzz')} 43 | } 44 | If ($Null -ne $IsRunning) { 45 | If ($IsRunning -eq $True) { 46 | $qparams += @{'filter[isRunning]' = 'true'} 47 | } Else { 48 | $qparams += @{'filter[isRunning]' = 'false'} 49 | } 50 | } 51 | } 52 | Else { 53 | #Parameter set "Show" is selected 54 | $Devices = @('') 55 | } 56 | 57 | ForEach ($configId IN $Id) { 58 | ForEach ($DeviceId IN $Devices) { 59 | $resource_uri = ('/v1/inventory/configuration') 60 | $qparams['page[first]'] = 100 61 | If (!($Null -eq $configID) -and $configId -gt '') { 62 | $resource_uri = ('/v1/inventory/configuration/{0}' -f $configId) 63 | $Null = $qparams.Remove('page[first]') 64 | } ElseIf (!($Null -eq $DeviceId) -and $DeviceId -gt '') { 65 | $qparams['filter[deviceId]'] = $DeviceId 66 | } Else { 67 | $Null = $qparams.Remove('filter[deviceId]') 68 | } 69 | 70 | Do { 71 | $attempt=0 72 | Do { 73 | $attempt+=1 74 | If ($attempt -gt 1) {Start-Sleep 2} 75 | Write-Debug "Testing $($Auvik_Base_URI + $resource_uri)$(If ($qparams.Count -gt 0) {'?' + $(($qparams.GetEnumerator() | ForEach-Object {"$($_.Name)=$($_.Value)"}) -join '&') })" 76 | $rest_output = try { 77 | $Null = $AuvikAPI_Headers.Add("Authorization", "Basic $x_api_authorization") 78 | Invoke-RestMethod -method 'GET' -uri ($Auvik_Base_URI + $resource_uri) -Headers $AuvikAPI_Headers -Body $qparams -ErrorAction SilentlyContinue 79 | } catch [System.Net.WebException] { 80 | $_.Exception.Response 81 | } catch { 82 | Write-Error $_ 83 | } finally { 84 | $Null = $AuvikAPI_Headers.Remove('Authorization') 85 | } 86 | Write-Verbose "Status Code Returned: $([int]$rest_output.StatusCode)" 87 | } Until ($([int]$rest_output.StatusCode) -ne 502 -or $attempt -ge 5) 88 | $data += $rest_output | Where-Object {$_.Data.ID -gt ''} 89 | If ($rest_output.links.next) {$qparams['page[after]'] = $rest_output.links.next -replace '%..','' -replace '.*?pageafter=([^&]*).*',"`$1"} 90 | Write-Debug "Page after value is $($qparams['page[after]'])" 91 | } Until (!($rest_output.links.next) -or $rest_output.links.next -eq '' ) 92 | } 93 | } 94 | } 95 | 96 | End { 97 | Return $data 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /AuvikAPI/Resources/Interface.ps1: -------------------------------------------------------------------------------- 1 | function Get-AuvikInterfacesInfo { 2 | [CmdletBinding(DefaultParameterSetName = 'index')] 3 | Param ( 4 | [Parameter(ParameterSetName = 'show')] 5 | [String[]]$Id, 6 | 7 | [Parameter(ParameterSetName = 'index')] 8 | [String[]]$Devices = '', 9 | 10 | [Parameter(ParameterSetName = 'index')] 11 | [ValidateSet('ethernet', 'wifi', 'bluetooth', 'cdma', 'coax', 'cpu', ` 12 | 'firewire', 'gsm', 'ieee8023AdLag', 'inferredWired', ` 13 | 'inferredWireless', 'linkAggregation', 'loopback', 'modem', ` 14 | 'wimax', 'optical', 'other', 'parallel', 'ppp', 'rs232', 'tunnel', ` 15 | 'unknown', 'usb', 'virtualBridge', 'virtualNic', 'virtualSwitch', ` 16 | 'vlan', 'distributedVirtualSwitch', 'interface')] 17 | [String]$InterfaceType = '', 18 | 19 | [Parameter(ParameterSetName = 'index')] 20 | [ValidateSet('online', 'offline', 'unreachable', 'testing', 'unknown', 'dormant', 'notPresent')] 21 | [String]$OperationalStatus = '', 22 | 23 | [Parameter(ParameterSetName = 'index')] 24 | [datetime]$ModifiedAfter, 25 | 26 | [Parameter(ParameterSetName = 'index')] 27 | [String[]]$Tenants = '', 28 | 29 | [Parameter(ParameterSetName = 'index')] 30 | [Nullable[Boolean]]$AdminStatus 31 | 32 | ) 33 | 34 | Begin { 35 | $data = @() 36 | $qparams = @{} 37 | $x_api_authorization = "$($Auvik_API_Credential.UserName):$([Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Auvik_API_Credential.Password)))" 38 | $x_api_authorization = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($x_api_authorization)) 39 | } 40 | 41 | Process { 42 | If ($PSCmdlet.ParameterSetName -eq 'index') { 43 | $Id = @('') 44 | If ($Tenants) { 45 | $qparams += @{'tenants' = $Tenants -join ','} 46 | } 47 | If ($InterfaceType) { 48 | $qparams += @{'filter[interfaceType]' = $InterfaceType} 49 | } 50 | If ($OperationalStatus) { 51 | $qparams += @{'filter[operationalStatus]' = $OperationalStatus} 52 | } 53 | If ($Null -ne $AdminStatus) { 54 | If ($AdminStatus -eq $True) { 55 | $qparams += @{'filter[adminStatus]' = 'true'} 56 | } Else { 57 | $qparams += @{'filter[adminStatus]' = 'false'} 58 | } 59 | } 60 | If ($ModifiedAfter) { 61 | $qparams += @{'filter[modifiedAfter]' = $ModifiedAfter.ToString('yyyy-MM-ddTHH:mm:ss.fffzzz')} 62 | } 63 | } 64 | Else { 65 | #Parameter set "Show" is selected 66 | $Devices = @('') 67 | } 68 | 69 | ForEach ($interfaceId IN $Id) { 70 | ForEach ($DeviceId IN $Devices) { 71 | $resource_uri = ('/v1/inventory/interface/info') 72 | If (!($Null -eq $interfaceId) -and $interfaceId -gt '') { 73 | $resource_uri = ('/v1/inventory/interface/info/{0}' -f $interfaceId) 74 | } ElseIf (!($Null -eq $DeviceId) -and $DeviceId -gt '') { 75 | $qparams['filter[parentDevice]'] = $DeviceId 76 | } Else { 77 | $Null = $qparams.Remove('filter[parentDevice]') 78 | } 79 | 80 | $attempt=0 81 | Do { 82 | $attempt+=1 83 | If ($attempt -gt 1) {Start-Sleep 2} 84 | Write-Debug "Testing $($Auvik_Base_URI + $resource_uri)$(If ($qparams.Count -gt 0) {'?' + $(($qparams.GetEnumerator() | ForEach-Object {"$($_.Name)=$($_.Value)"}) -join '&') })" 85 | $rest_output = try { 86 | $Null = $AuvikAPI_Headers.Add("Authorization", "Basic $x_api_authorization") 87 | Invoke-RestMethod -method 'GET' -uri ($Auvik_Base_URI + $resource_uri) -Headers $AuvikAPI_Headers -Body $qparams -ErrorAction SilentlyContinue 88 | } catch [System.Net.WebException] { 89 | $_.Exception.Response 90 | } catch { 91 | Write-Error $_ 92 | } finally { 93 | $Null = $AuvikAPI_Headers.Remove('Authorization') 94 | } 95 | Write-Verbose "Status Code Returned: $([int]$rest_output.StatusCode)" 96 | } Until ($([int]$rest_output.StatusCode) -ne 502 -or $attempt -ge 5) 97 | $data += $rest_output | Where-Object {$_.Data.ID -gt ''} 98 | } 99 | } 100 | } 101 | 102 | End { 103 | Return $data 104 | } 105 | 106 | } 107 | 108 | -------------------------------------------------------------------------------- /AuvikAPI/Resources/AlertHistory.ps1: -------------------------------------------------------------------------------- 1 | function Get-AuvikAlertsInfo { 2 | [CmdletBinding(DefaultParameterSetName = 'index')] 3 | Param ( 4 | [Parameter(ParameterSetName = 'show')] 5 | [String[]]$Id, 6 | 7 | [Parameter(ParameterSetName = 'index')] 8 | [String]$AlertSpecificationID = '', 9 | 10 | [Parameter(ParameterSetName = 'index')] 11 | [ValidateSet('unknown','emergency','critical','warning','info')] 12 | [String]$Severity = '', 13 | 14 | [Parameter(ParameterSetName = 'index')] 15 | [ValidateSet('created', 'resolved', 'paused', 'unpaused')] 16 | [String]$Status = '', 17 | 18 | [Parameter(ParameterSetName = 'index')] 19 | [String[]]$Entities = '', 20 | 21 | [Parameter(ParameterSetName = 'index')] 22 | [Nullable[Boolean]]$Dismissed, 23 | 24 | [Parameter(ParameterSetName = 'index')] 25 | [Nullable[Boolean]]$Dispatched, 26 | 27 | [Parameter(ParameterSetName = 'index')] 28 | [datetime]$DetectedAfter, 29 | 30 | [Parameter(ParameterSetName = 'index')] 31 | [datetime]$DetectedBefore, 32 | 33 | [Parameter(ParameterSetName = 'index')] 34 | [String[]]$Tenants = '' 35 | 36 | ) 37 | 38 | Begin { 39 | $data = @() 40 | $qparams = @{} 41 | $x_api_authorization = "$($Auvik_API_Credential.UserName):$([Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Auvik_API_Credential.Password)))" 42 | $x_api_authorization = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($x_api_authorization)) 43 | } 44 | 45 | Process { 46 | If ($PSCmdlet.ParameterSetName -eq 'index') { 47 | $Id = @('') 48 | If ($Tenants) { 49 | $qparams += @{'tenants' = $Tenants -join ','} 50 | } 51 | If ($AlertSpecificationID) { 52 | $qparams += @{'filter[alertSpecificationId]' = $AlertSpecificationID} 53 | } 54 | If ($Severity) { 55 | $qparams += @{'filter[severity]' = $Severity} 56 | } 57 | If ($Status) { 58 | $qparams += @{'filter[status]' = $Status} 59 | } 60 | If ($Null -ne $Dismissed) { 61 | If ($Dismissed -eq $True) { 62 | $qparams += @{'filter[dismissed]' = 'true'} 63 | } Else { 64 | $qparams += @{'filter[dismissed]' = 'false'} 65 | } 66 | } 67 | If ($Null -ne $Dispatched) { 68 | If ($Dispatched -eq $True) { 69 | $qparams += @{'filter[dispatched]' = 'true'} 70 | } Else { 71 | $qparams += @{'filter[dispatched]' = 'false'} 72 | } 73 | } 74 | If ($DetectedAfter) { 75 | $qparams += @{'filter[detectedTimeAfter]' = $DetectedAfter.ToString('yyyy-MM-ddTHH:mm:ss.fffzzz')} 76 | } 77 | If ($DetectedBefore) { 78 | $qparams += @{'filter[detectedTimeBefore]' = $DetectedBefore.ToString('yyyy-MM-ddTHH:mm:ss.fffzzz')} 79 | } 80 | } 81 | Else { 82 | #Parameter set "Show" is selected 83 | $Entities = @('') 84 | } 85 | 86 | ForEach ($alertId IN $Id) { 87 | ForEach ($entityID IN $Entities) { 88 | $resource_uri = '/v1/alert/history/info' 89 | If (!($Null -eq $alertId) -and $alertId -gt '') { 90 | $resource_uri = ('/v1/alert/history/info/{0}' -f $alertId) 91 | } ElseIf (!($Null -eq $entityID) -and $entityID -gt '') { 92 | $qparams['filter[entityId]'] = $entityID 93 | } Else { 94 | $Null = $qparams.Remove('filter[entityId]') 95 | } 96 | 97 | $attempt=0 98 | Do { 99 | $attempt+=1 100 | If ($attempt -gt 1) {Start-Sleep 2} 101 | Write-Debug "Testing $($Auvik_Base_URI + $resource_uri)$(If ($qparams.Count -gt 0) {'?' + $(($qparams.GetEnumerator() | ForEach-Object {"$($_.Name)=$($_.Value)"}) -join '&') })" 102 | $rest_output = try { 103 | $Null = $AuvikAPI_Headers.Add("Authorization", "Basic $x_api_authorization") 104 | Invoke-RestMethod -method 'GET' -uri ($Auvik_Base_URI + $resource_uri) -Headers $AuvikAPI_Headers -Body $qparams -ErrorAction SilentlyContinue 105 | } catch [System.Net.WebException] { 106 | $_.Exception.Response 107 | } catch { 108 | Write-Error $_ 109 | } finally { 110 | $Null = $AuvikAPI_Headers.Remove('Authorization') 111 | } 112 | Write-Verbose "Status Code Returned: $([int]$rest_output.StatusCode)" 113 | } Until ($([int]$rest_output.StatusCode) -ne 502 -or $attempt -ge 5) 114 | $data += $rest_output 115 | } 116 | } 117 | } 118 | 119 | End { 120 | Return $data 121 | } 122 | 123 | } 124 | -------------------------------------------------------------------------------- /AuvikAPI/Resources/Tenants.ps1: -------------------------------------------------------------------------------- 1 | function Get-AuvikTenants { 2 | 3 | $resource_uri = ('/v1/tenants') 4 | 5 | $data = @{} 6 | 7 | $x_api_authorization = "$($Auvik_API_Credential.UserName):$([Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Auvik_API_Credential.Password)))" 8 | $x_api_authorization = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($x_api_authorization)) 9 | 10 | $attempt=0 11 | Do { 12 | $attempt+=1 13 | If ($attempt -gt 1) {Start-Sleep 2} 14 | Write-Debug "Testing $($Auvik_Base_URI + $resource_uri)" 15 | $rest_output = try { 16 | $Null = $AuvikAPI_Headers.Add("Authorization", "Basic $x_api_authorization") 17 | Invoke-RestMethod -method 'GET' -uri ($Auvik_Base_URI + $resource_uri) -Headers $AuvikAPI_Headers ` 18 | -ErrorAction SilentlyContinue 19 | } catch [System.Net.WebException] { 20 | $_.Exception.Response 21 | } catch { 22 | Write-Error $_ 23 | } finally { 24 | $Null = $AuvikAPI_Headers.Remove('Authorization') 25 | } 26 | } Until ($([int]$rest_output.StatusCode) -ne 502 -or $attempt -ge 5) 27 | $data = $rest_output | Select-Object -ExpandProperty 'Data' -EA 0 28 | Return $data 29 | } 30 | 31 | function Get-AuvikTenantsDetail { 32 | 33 | [CmdletBinding(DefaultParameterSetName = 'show')] 34 | Param ( 35 | [Parameter(ParameterSetName = 'show')] 36 | [String[]]$Id, 37 | 38 | [Parameter(ParameterSetName = 'show')] 39 | [Alias('Tenant')] 40 | [String]$PrimaryTenant 41 | ) 42 | 43 | Begin { 44 | $data = @() 45 | $qparams = @{} 46 | $x_api_authorization = "$($Auvik_API_Credential.UserName):$([Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Auvik_API_Credential.Password)))" 47 | $x_api_authorization = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($x_api_authorization)) 48 | 49 | If (!($PrimaryTenant)) { 50 | $PrimaryTenant = Get-AuvikTenants | Sort-Object -Property @{Expression={$_.attributes.tenantType -eq 'multiClient' -and !($_.relationships)}; Ascending=$False} | Select-Object -ExpandProperty attributes | Select-Object -ExpandProperty domainprefix -First 1 51 | Write-Debug "Primary Tenant detected as $PrimaryTenant" 52 | } 53 | If (!($PrimaryTenant)) { 54 | Write-Error "Failed to resolve Primary Tenant Name" 55 | } 56 | } 57 | 58 | Process { 59 | 60 | If ($PSCmdlet.ParameterSetName -eq 'show') { 61 | If(($ID).Count -eq 0) {$Id = @('')} 62 | } 63 | # Write-Debug "IDs: $($ID), has $(($ID).Count) members. @(,`$ID) has $(@(,$ID).Count) members." 64 | 65 | ForEach ($TenantId IN $Id) { 66 | $resource_uri = ('/v1/tenants/detail') 67 | $qparams['tenantDomainPrefix']=$PrimaryTenant 68 | # $qparams['page[first]'] = 100 69 | If (!($Null -eq $TenantID) -and $TenantId -gt '') { 70 | $resource_uri = $resource_uri + ('/{0}' -f $TenantId) 71 | } 72 | 73 | Do { 74 | $attempt=0 75 | Do { 76 | $attempt+=1 77 | If ($attempt -gt 1) {Start-Sleep 2} 78 | Write-Debug "Testing $($Auvik_Base_URI + $resource_uri)$(If ($qparams.Count -gt 0) {'?' + $(($qparams.GetEnumerator() | ForEach-Object {"$($_.Name)=$($_.Value)"}) -join '&') })" 79 | $rest_output = try { 80 | $Null = $AuvikAPI_Headers.Add("Authorization", "Basic $x_api_authorization") 81 | Invoke-RestMethod -method 'GET' -uri ($Auvik_Base_URI + $resource_uri) -Headers $AuvikAPI_Headers -Body $qparams -ErrorAction SilentlyContinue 82 | } catch [System.Net.WebException] { 83 | $_.Exception.Response 84 | } catch { 85 | Write-Error $_ 86 | } finally { 87 | $Null = $AuvikAPI_Headers.Remove('Authorization') 88 | } 89 | Write-Verbose "Status Code Returned: $([int]$rest_output.StatusCode)" 90 | } Until ($([int]$rest_output.StatusCode) -ne 502 -or $attempt -ge 5) 91 | $data += $rest_output | Where-Object {$_.Data.ID -gt ''} | Select-Object -ExpandProperty 'Data' -EA 0 92 | # If ($rest_output.links.next) {$qparams['page[after]'] = $rest_output.links.next -replace '%..','' -replace '.*?pageafter=([^&]*).*',"`$1"} 93 | # Write-Debug "Page after value is $($qparams['page[after]'])" 94 | } Until (!($rest_output.links.next) -or $rest_output.links.next -eq '' ) 95 | } 96 | } 97 | 98 | End { 99 | Return $data 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /AuvikAPI/AuvikAPI.psd1: -------------------------------------------------------------------------------- 1 | # 2 | # Module manifest for module 'AuvikAPI' 3 | # 4 | # Created by: Darren White 5 | # 6 | # Created on: 12/13/2018 7 | # 8 | 9 | @{ 10 | 11 | # Script module or binary module file associated with this manifest 12 | RootModule = '.\AuvikAPI.psm1' 13 | 14 | # Version number of this module. 15 | # Follows https://semver.org Semantic Versioning 2.0.0 16 | # Given a version number MAJOR.MINOR.PATCH, increment the: 17 | # -- MAJOR version when you make incompatible API changes, 18 | # -- MINOR version when you add functionality in a backwards-compatible manner, and 19 | # -- PATCH version when you make backwards-compatible bug fixes. 20 | ModuleVersion = '1.1.1' 21 | 22 | # ID used to uniquely identify this module 23 | #GUID = '' 24 | 25 | # Author of this module 26 | Author = 'Darren White' 27 | 28 | # Company or vendor of this module 29 | CompanyName = 'Auvik' 30 | 31 | # Description of the functionality provided by this module 32 | Description = 'This module provides a PowerShell wrapper for the Auvik API.' 33 | 34 | # Copyright information of this module 35 | Copyright = 'https://github.com/DarrenWhite99/Auvik-PowerShell-Module/blob/master/LICENSE' 36 | 37 | # Minimum version of the Windows PowerShell engine required by this module 38 | PowerShellVersion = '3.0' 39 | 40 | # Name of the Windows PowerShell host required by this module 41 | # PowerShellHostName = '' 42 | 43 | # Minimum version of the Windows PowerShell host required by this module 44 | # PowerShellHostVersion = '' 45 | 46 | # Minimum version of the .NET Framework required by this module 47 | # DotNetFrameworkVersion = '' 48 | 49 | # Minimum version of the common language runtime (CLR) required by this module 50 | # CLRVersion = '' 51 | 52 | # Processor architecture (None, X86, Amd64) required by this module 53 | # ProcessorArchitecture = '' 54 | 55 | # Modules that must be imported into the global environment prior to importing this module 56 | # RequiredModules = @() 57 | 58 | # Assemblies that must be loaded prior to importing this module 59 | # RequiredAssemblies = @() 60 | 61 | # Script files (.ps1) that are run in the caller's environment prior to importing this module 62 | # ScriptsToProcess = @() 63 | 64 | # Type files (.ps1xml) to be loaded when importing this module 65 | # TypesToProcess = @() 66 | 67 | # Format files (.ps1xml) to be loaded when importing this module 68 | # FormatsToProcess = @() 69 | 70 | # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess 71 | NestedModules = 'Internal/BaseURI.ps1', 72 | 'Internal/APICredential.ps1', 73 | 'Internal/ModuleSettings.ps1', 74 | 'Resources/AlertHistory.ps1', 75 | 'Resources/Authentication.ps1', 76 | 'Resources/Billing.ps1', 77 | 'Resources/Component.ps1', 78 | 'Resources/Configuration.ps1', 79 | 'Resources/Device.ps1', 80 | 'Resources/Entity.ps1', 81 | 'Resources/Interface.ps1', 82 | 'Resources/MetaData.ps1', 83 | 'Resources/Network.ps1', 84 | 'Resources/Tenants.ps1' 85 | 86 | # Functions to export from this module 87 | FunctionsToExport = 'Add-AuvikAPICredential', 88 | 'Confirm-AuvikAPICredential', 89 | 'Get-AuvikAPICredential', 90 | 'Remove-AuvikAPICredential', 91 | 92 | 'Add-AuvikBaseURI', 93 | 'Get-AuvikBaseURI', 94 | 'Remove-AuvikBaseURI', 95 | 96 | 'Export-AuvikModuleSettings', 97 | 'Import-AuvikModuleSettings', 98 | 99 | 'Get-AuvikAlertsInfo', 100 | 101 | 'Get-AuvikBillingInfo', 102 | 'Get-AuvikBillingDetails', 103 | 104 | 'Get-AuvikComponentsInfo', 105 | 106 | 'Get-AuvikDeviceConfiguration', 107 | 108 | 'Get-AuvikDevicesInfo', 109 | 'Get-AuvikDevicesDetails', 110 | 'Get-AuvikDevicesExtendedDetails', 111 | 112 | 'Get-AuvikEntityAudits', 113 | 'Get-AuvikEntityNotes', 114 | 115 | 'Get-AuvikInterfacesInfo', 116 | 117 | 'Get-AuvikMetaField', 118 | 119 | 'Get-AuvikNetworksInfo', 120 | 'Get-AuvikNetworksDetails', 121 | 122 | 'Get-AuvikTenants', 123 | 'Get-AuvikTenantsDetail' 124 | 125 | #FunctionsToExport = '*' 126 | 127 | # Cmdlets to export from this module 128 | CmdletsToExport = @() 129 | 130 | # Variables to export from this module 131 | VariablesToExport = '*' 132 | 133 | # Aliases to export from this module 134 | AliasesToExport = '*' 135 | 136 | # List of all modules packaged with this module 137 | # ModuleList = @() 138 | 139 | # List of all files packaged with this module 140 | # FileList = @() 141 | 142 | # Private data to pass to the module specified in RootModule/ModuleToProcess 143 | # PrivateData = '' 144 | 145 | # HelpInfo URI of this module 146 | HelpInfoURI = 'https://github.com/DarrenWhite99/Auvik-PowerShell-Module' 147 | 148 | # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. 149 | # DefaultCommandPrefix = '' 150 | 151 | } -------------------------------------------------------------------------------- /AuvikAPI/Resources/Entity.ps1: -------------------------------------------------------------------------------- 1 | function Get-AuvikEntityAudits { 2 | [CmdletBinding(DefaultParameterSetName = 'index')] 3 | Param ( 4 | [Parameter(ParameterSetName = 'show')] 5 | [String[]]$Id, 6 | 7 | [Parameter(ParameterSetName = 'index')] 8 | [String]$User = '', 9 | 10 | [Parameter(ParameterSetName = 'index')] 11 | [ValidateSet('unknown', 'tunnel', 'terminal')] 12 | [String]$Category = '', 13 | 14 | [Parameter(ParameterSetName = 'index')] 15 | [ValidateSet('unknown', 'initiated', 'created', 'closed', 'failed')] 16 | [String]$Status = '', 17 | 18 | [Parameter(ParameterSetName = 'index')] 19 | [datetime]$ModifiedAfter, 20 | 21 | [Parameter(ParameterSetName = 'index')] 22 | [String[]]$Tenants = '' 23 | 24 | ) 25 | 26 | Begin { 27 | $data = @() 28 | $qparams = @{} 29 | $x_api_authorization = "$($Auvik_API_Credential.UserName):$([Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Auvik_API_Credential.Password)))" 30 | $x_api_authorization = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($x_api_authorization)) 31 | } 32 | 33 | Process { 34 | 35 | If ($PSCmdlet.ParameterSetName -eq 'index') { 36 | $Id = @('') 37 | If ($Tenants) { 38 | $qparams += @{'tenants' = $Tenants -join ','} 39 | } 40 | If ($User) { 41 | $qparams += @{'filter[user]' = $User} 42 | } 43 | If ($Category) { 44 | $qparams += @{'filter[category]' = $Category} 45 | } 46 | If ($Status) { 47 | $qparams += @{'filter[status]' = $Status} 48 | } 49 | If ($ModifiedAfter) { 50 | $qparams += @{'filter[modifiedAfter]' = $ModifiedAfter.ToString('yyyy-MM-ddTHH:mm:ss.fffzzz')} 51 | } 52 | } 53 | Else { 54 | #Parameter set "Show" is selected 55 | } 56 | 57 | ForEach ($entityAuditId IN $Id) { 58 | $resource_uri = ('/v1/inventory/entity/audit') 59 | If (!($Null -eq $entityAuditId) -and $entityAuditId -gt '') { 60 | $resource_uri = ('/v1/inventory/entity/audit/{0}' -f $entityAuditId) 61 | } 62 | 63 | $attempt=0 64 | Do { 65 | $attempt+=1 66 | If ($attempt -gt 1) {Start-Sleep 2} 67 | Write-Debug "Testing $($Auvik_Base_URI + $resource_uri)$(If ($qparams.Count -gt 0) {'?' + $(($qparams.GetEnumerator() | ForEach-Object {"$($_.Name)=$($_.Value)"}) -join '&') })" 68 | $rest_output = try { 69 | $Null = $AuvikAPI_Headers.Add("Authorization", "Basic $x_api_authorization") 70 | Invoke-RestMethod -method 'GET' -uri ($Auvik_Base_URI + $resource_uri) -Headers $AuvikAPI_Headers -Body $qparams -ErrorAction SilentlyContinue 71 | } catch [System.Net.WebException] { 72 | $_.Exception.Response 73 | } catch { 74 | Write-Error $_ 75 | } finally { 76 | $Null = $AuvikAPI_Headers.Remove('Authorization') 77 | } 78 | Write-Verbose "Status Code Returned: $([int]$rest_output.StatusCode)" 79 | } Until ($([int]$rest_output.StatusCode) -ne 502 -or $attempt -ge 5) 80 | $data += $rest_output | Where-Object {$_.Data.ID -gt ''} 81 | } 82 | } 83 | 84 | End { 85 | Return $data 86 | } 87 | 88 | } 89 | 90 | function Get-AuvikEntityNotes { 91 | [CmdletBinding(DefaultParameterSetName = 'index')] 92 | Param ( 93 | [Parameter(ParameterSetName = 'show')] 94 | [String[]]$Id, 95 | 96 | [Parameter(ParameterSetName = 'index')] 97 | [String[]]$Entities = '', 98 | 99 | [Parameter(ParameterSetName = 'index')] 100 | [String]$EntityName = '', 101 | 102 | [Parameter(ParameterSetName = 'index')] 103 | [String]$User = '', 104 | 105 | [Parameter(ParameterSetName = 'index')] 106 | [ValidateSet('root','device','network','interface')] 107 | [String]$Type = '', 108 | 109 | [Parameter(ParameterSetName = 'index')] 110 | [datetime]$ModifiedAfter, 111 | 112 | [Parameter(ParameterSetName = 'index')] 113 | [String[]]$Tenants = '' 114 | 115 | ) 116 | 117 | Begin { 118 | $data = @() 119 | $qparams = @{} 120 | $x_api_authorization = "$($Auvik_API_Credential.UserName):$([Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Auvik_API_Credential.Password)))" 121 | $x_api_authorization = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($x_api_authorization)) 122 | } 123 | 124 | Process { 125 | 126 | If ($PSCmdlet.ParameterSetName -eq 'index') { 127 | $Id = @('') 128 | If ($Tenants) { 129 | $qparams += @{'tenants' = $Tenants -join ','} 130 | } 131 | If ($EntityName) { 132 | $qparams += @{'filter[entityName]' = $EntityName} 133 | } 134 | If ($Type) { 135 | $qparams += @{'filter[entityType]' = $Type} 136 | } 137 | If ($User) { 138 | $qparams += @{'filter[lastModifiedBy]' = $User} 139 | } 140 | If ($ModifiedAfter) { 141 | $qparams += @{'filter[modifiedAfter]' = $ModifiedAfter.ToString('yyyy-MM-ddTHH:mm:ss.fffzzz')} 142 | } 143 | } 144 | Else { 145 | #Parameter set "Show" is selected 146 | $Entities = @('') 147 | } 148 | 149 | ForEach ($entityNoteId IN $Id) { 150 | ForEach ($entityID IN $Entities) { 151 | $resource_uri = ('/v1/inventory/entity/note') 152 | If (!($Null -eq $entityNoteId) -and $entityNoteId -gt '') { 153 | $resource_uri = ('/v1/inventory/entity/note/{0}' -f $entityNoteId) 154 | } ElseIf (!($Null -eq $entityID) -and $entityID -gt '') { 155 | $qparams['filter[entityId]'] = $entityID 156 | } Else { 157 | $Null = $qparams.Remove('filter[entityId]') 158 | } 159 | 160 | $attempt=0 161 | Do { 162 | $attempt+=1 163 | If ($attempt -gt 1) {Start-Sleep 2} 164 | Write-Debug "Testing $($Auvik_Base_URI + $resource_uri)$(If ($qparams.Count -gt 0) {'?' + $(($qparams.GetEnumerator() | ForEach-Object {"$($_.Name)=$($_.Value)"}) -join '&') })" 165 | $rest_output = try { 166 | $Null = $AuvikAPI_Headers.Add("Authorization", "Basic $x_api_authorization") 167 | Invoke-RestMethod -method 'GET' -uri ($Auvik_Base_URI + $resource_uri) -Headers $AuvikAPI_Headers -Body $qparams -ErrorAction SilentlyContinue 168 | } catch [System.Net.WebException] { 169 | $_.Exception.Response 170 | } catch { 171 | Write-Error $_ 172 | } finally { 173 | $Null = $AuvikAPI_Headers.Remove('Authorization') 174 | } 175 | Write-Verbose "Status Code Returned: $([int]$rest_output.StatusCode)" 176 | } Until ($([int]$rest_output.StatusCode) -ne 502 -or $attempt -ge 5) 177 | $data += $rest_output | Where-Object {$_.Data.ID -gt ''} 178 | } 179 | } 180 | } 181 | 182 | End { 183 | Return $data 184 | } 185 | 186 | } 187 | 188 | -------------------------------------------------------------------------------- /AuvikAPI/Resources/Network.ps1: -------------------------------------------------------------------------------- 1 | function Get-AuvikNetworksInfo { 2 | [CmdletBinding(DefaultParameterSetName = 'index')] 3 | Param ( 4 | [Parameter(ParameterSetName = 'show')] 5 | [String[]]$Id, 6 | 7 | [Parameter(ParameterSetName = 'index')] 8 | [String[]]$Devices = '', 9 | 10 | [Parameter(ParameterSetName = 'index')] 11 | [ValidateSet('routed', 'vlan', 'wifi', 'loopback', 'network', 'layer2', 'internet')] 12 | [String]$NetworkType = '', 13 | 14 | [Parameter(ParameterSetName = 'index')] 15 | [ValidateSet('true','false','notAllowed','unknown')] 16 | [String]$ScanStatus = '', 17 | 18 | [Parameter(ParameterSetName = 'index')] 19 | [datetime]$ModifiedAfter, 20 | 21 | [Parameter(ParameterSetName = 'index')] 22 | [String[]]$Tenants = '', 23 | 24 | [Parameter(ParameterSetName = 'show')] 25 | [Parameter(ParameterSetName = 'index')] 26 | [ValidateSet('scope', 'primaryCollector', 'secondaryCollectors', 'collectorSelection', 'excludedIpAddresses')] 27 | [String[]]$IncludeDetailFields = '' 28 | 29 | ) 30 | 31 | Begin { 32 | $data = @() 33 | $qparams = @{} 34 | $x_api_authorization = "$($Auvik_API_Credential.UserName):$([Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Auvik_API_Credential.Password)))" 35 | $x_api_authorization = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($x_api_authorization)) 36 | } 37 | 38 | Process { 39 | If ($IncludeDetailFields) { 40 | $qparams += @{'include' = 'networkDetail'; 'fields[networkDetail]' = $IncludeDetailFields -join ','} 41 | } 42 | 43 | If ($PSCmdlet.ParameterSetName -eq 'index') { 44 | $Id = @('') 45 | If ($Tenants) { 46 | $qparams += @{'tenants' = $Tenants -join ','} 47 | } 48 | If ($NetworkType) { 49 | $qparams += @{'filter[networkType]' = $NetworkType} 50 | } 51 | If ($ScanStatus) { 52 | $qparams += @{'filter[scanStatus]' = $ScanStatus} 53 | } 54 | If ($ModifiedAfter) { 55 | $qparams += @{'filter[modifiedAfter]' = $ModifiedAfter.ToString('yyyy-MM-ddTHH:mm:ss.fffzzz')} 56 | } 57 | } 58 | Else { 59 | #Parameter set "Show" is selected 60 | $Devices = @('') 61 | } 62 | 63 | ForEach ($networkId IN $Id) { 64 | ForEach ($DeviceId IN $Devices) { 65 | $resource_uri = ('/v1/inventory/network/info') 66 | If (!($Null -eq $networkId) -and $networkId -gt '') { 67 | $resource_uri = ('/v1/inventory/network/info/{0}' -f $networkId) 68 | } ElseIf (!($Null -eq $DeviceId) -and $DeviceId -gt '') { 69 | $qparams['filter[devices]'] = $DeviceId 70 | } Else { 71 | $Null = $qparams.Remove('filter[devices]') 72 | } 73 | 74 | $attempt=0 75 | Do { 76 | $attempt+=1 77 | If ($attempt -gt 1) {Start-Sleep 2} 78 | Write-Debug "Testing $($Auvik_Base_URI + $resource_uri)$(If ($qparams.Count -gt 0) {'?' + $(($qparams.GetEnumerator() | ForEach-Object {"$($_.Name)=$($_.Value)"}) -join '&') })" 79 | $rest_output = try { 80 | $Null = $AuvikAPI_Headers.Add("Authorization", "Basic $x_api_authorization") 81 | Invoke-RestMethod -method 'GET' -uri ($Auvik_Base_URI + $resource_uri) -Headers $AuvikAPI_Headers -Body $qparams -ErrorAction SilentlyContinue 82 | } catch [System.Net.WebException] { 83 | $_.Exception.Response 84 | } catch { 85 | Write-Error $_ 86 | } finally { 87 | $Null = $AuvikAPI_Headers.Remove('Authorization') 88 | } 89 | Write-Verbose "Status Code Returned: $([int]$rest_output.StatusCode)" 90 | } Until ($([int]$rest_output.StatusCode) -ne 502 -or $attempt -ge 5) 91 | $data += $rest_output | Where-Object {$_.Data.ID -gt ''} 92 | } 93 | } 94 | } 95 | 96 | End { 97 | Return $data 98 | } 99 | 100 | } 101 | 102 | function Get-AuvikNetworksDetails { 103 | [CmdletBinding(DefaultParameterSetName = 'index')] 104 | Param ( 105 | [Parameter(ParameterSetName = 'show')] 106 | [String[]]$Id, 107 | 108 | [Parameter(ParameterSetName = 'index')] 109 | [String[]]$Devices = '', 110 | 111 | [Parameter(ParameterSetName = 'index')] 112 | [ValidateSet('routed', 'vlan', 'wifi', 'loopback', 'network', 'layer2', 'internet')] 113 | [String]$NetworkType = '', 114 | 115 | [Parameter(ParameterSetName = 'index')] 116 | [ValidateSet('true','false','notAllowed','unknown')] 117 | [String]$ScanStatus = '', 118 | 119 | [Parameter(ParameterSetName = 'index')] 120 | [ValidateSet('private', 'public')] 121 | [String]$Scope = '', 122 | 123 | [Parameter(ParameterSetName = 'index')] 124 | [datetime]$ModifiedAfter, 125 | 126 | [Parameter(ParameterSetName = 'index')] 127 | [String[]]$Tenants = '' 128 | 129 | ) 130 | 131 | Begin { 132 | $data = @() 133 | $qparams = @{} 134 | $x_api_authorization = "$($Auvik_API_Credential.UserName):$([Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Auvik_API_Credential.Password)))" 135 | $x_api_authorization = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($x_api_authorization)) 136 | } 137 | 138 | Process { 139 | If ($PSCmdlet.ParameterSetName -eq 'index') { 140 | $Id = @('') 141 | If ($Tenants) { 142 | $qparams += @{'tenants' = $Tenants -join ','} 143 | } 144 | If ($NetworkType) { 145 | $qparams += @{'filter[networkType]' = $NetworkType} 146 | } 147 | If ($ScanStatus) { 148 | $qparams += @{'filter[scanStatus]' = $ScanStatus} 149 | } 150 | If ($Scope) { 151 | $qparams += @{'filter[scope]' = $Scope} 152 | } 153 | If ($ModifiedAfter) { 154 | $qparams += @{'filter[modifiedAfter]' = $ModifiedAfter.ToString('yyyy-MM-ddTHH:mm:ss.fffzzz')} 155 | } 156 | } 157 | Else { 158 | #Parameter set "Show" is selected 159 | $Devices = @('') 160 | } 161 | 162 | ForEach ($networkId IN $Id) { 163 | ForEach ($DeviceId IN $Devices) { 164 | $resource_uri = ('/v1/inventory/network/detail') 165 | If (!($Null -eq $networkId) -and $networkId -gt '') { 166 | $resource_uri = ('/v1/inventory/network/detail/{0}' -f $networkId) 167 | } ElseIf (!($Null -eq $DeviceId) -and $DeviceId -gt '') { 168 | $qparams['filter[devices]'] = $DeviceId 169 | } Else { 170 | $Null = $qparams.Remove('filter[devices]') 171 | } 172 | 173 | $attempt=0 174 | Do { 175 | $attempt+=1 176 | If ($attempt -gt 1) {Start-Sleep 2} 177 | Write-Debug "Testing $($Auvik_Base_URI + $resource_uri)$(If ($qparams.Count -gt 0) { $resource_uri += '?' + $(($qparams.GetEnumerator() | ForEach-Object {"$($_.Name)=$($_.Value)"}) -join '&') })" 178 | $rest_output = try { 179 | $Null = $AuvikAPI_Headers.Add("Authorization", "Basic $x_api_authorization") 180 | Invoke-RestMethod -method 'GET' -uri ($Auvik_Base_URI + $resource_uri) -Headers $AuvikAPI_Headers -Body $qparams -ErrorAction SilentlyContinue 181 | } catch [System.Net.WebException] { 182 | $_.Exception.Response 183 | } catch { 184 | Write-Error $_ 185 | } finally { 186 | $Null = $AuvikAPI_Headers.Remove('Authorization') 187 | } 188 | Write-Verbose "Status Code Returned: $([int]$rest_output.StatusCode)" 189 | } Until ($([int]$rest_output.StatusCode) -ne 502 -or $attempt -ge 5) 190 | $data += $rest_output | Where-Object {$_.Data.ID -gt ''} 191 | } 192 | } 193 | } 194 | 195 | End { 196 | Return $data 197 | } 198 | 199 | } 200 | 201 | -------------------------------------------------------------------------------- /AuvikAPI/Resources/Billing.ps1: -------------------------------------------------------------------------------- 1 | function Get-AuvikBillingInfo { 2 | [CmdletBinding(DefaultParameterSetName = 'show')] 3 | Param ( 4 | [Parameter(ParameterSetName = 'show')] 5 | [Alias('Tenant')] 6 | [String]$PrimaryTenant, 7 | 8 | [Parameter(ParameterSetName = 'show')] 9 | [String]$QueryTenant, 10 | 11 | [Parameter(ParameterSetName = 'show')] 12 | [ValidateSet('all', 'children')] 13 | [String]$Descendants = '', 14 | 15 | [Parameter(ParameterSetName = 'show')] 16 | [Alias('Date')] 17 | [datetime]$FromDate, 18 | 19 | [Parameter(ParameterSetName = 'show')] 20 | [datetime]$ToDate, 21 | 22 | [Parameter(ParameterSetName = 'show', Mandatory = $false)] 23 | [switch]$Daily=$False 24 | 25 | ) 26 | 27 | Begin { 28 | $data = @() 29 | $qparams = @{} 30 | $x_api_authorization = "$($Auvik_API_Credential.UserName):$([Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Auvik_API_Credential.Password)))" 31 | $x_api_authorization = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($x_api_authorization)) 32 | 33 | If (!($PrimaryTenant)) { 34 | $PrimaryTenant = Get-AuvikTenants | Select-Object -ExpandProperty attributes | Sort-Object -Property @{Expression={$_.tenantType -eq 'multiClient'}; Ascending=$False} | Select-Object -ExpandProperty domainprefix -First 1 35 | } 36 | If (!($PrimaryTenant)) { 37 | Write-Error "Failed to resolve Primary Tenant Name" 38 | } 39 | 40 | If ($PSCmdlet.ParameterSetName -eq 'show') { 41 | If ($QueryTenant) { 42 | $qparams += @{'tenant' = $QueryTenant} 43 | } Else { 44 | $qparams += @{'tenant' = $PrimaryTenant} 45 | } 46 | If ($Descendants) { 47 | $qparams += @{'descendants' = $Descendants} 48 | } 49 | If (!($FromDate)) { 50 | If ($ToDate) { 51 | $FromDate = $ToDate 52 | } Else { 53 | $FromDate=(Get-Date).AddDays(-1) 54 | } 55 | } 56 | $qparams += @{'from' = $FromDate.ToString('yyyy-MM-dd')} 57 | If ($ToDate) { 58 | $qparams += @{'to' = $FromDate.ToString('yyyy-MM-dd')} 59 | } Else { 60 | If ($Daily -eq $True) { 61 | $qparams += @{'to' = ((Get-Date).AddDays(-1)).ToString('yyyy-MM-dd')} 62 | } Else { 63 | $qparams += @{'to' = $FromDate.ToString('yyyy-MM-dd')} 64 | } 65 | } 66 | If ($Null -ne $Daily) { 67 | If ($Daily -eq $True) { 68 | $qparams += @{'daily' = 'true'} 69 | } Else { 70 | $qparams += @{'daily' = 'false'} 71 | } 72 | } 73 | } 74 | Else { 75 | #Unknown Parameter set is selected 76 | } 77 | 78 | } 79 | 80 | Process { 81 | 82 | $resource_uri = ('/api/billing/v1/summary') 83 | $x_Base_URI = $Auvik_Base_URI -replace '(?<=//)[^.]+',$PrimaryTenant 84 | 85 | $attempt=0 86 | Do { 87 | $attempt+=1 88 | If ($attempt -gt 1) {Start-Sleep 2} 89 | Write-Debug "Testing $($x_Base_URI + $resource_uri)$(If ($qparams.Count -gt 0) {'?' + $(($qparams.GetEnumerator() | ForEach-Object {"$($_.Name)=$($_.Value)"}) -join '&') })" 90 | $rest_output = try { 91 | $Null = $AuvikAPI_Headers.Add("Authorization", "Basic $x_api_authorization") 92 | Invoke-RestMethod -method 'GET' -uri ($x_Base_URI + $resource_uri) -Headers $AuvikAPI_Headers -Body $qparams -ErrorAction SilentlyContinue 93 | } catch [System.Net.WebException] { 94 | $_.Exception.Response 95 | } catch { 96 | Write-Error $_ 97 | } finally { 98 | $Null = $AuvikAPI_Headers.Remove('Authorization') 99 | } 100 | Write-Verbose "Status Code Returned: $([int]$rest_output.StatusCode)" 101 | } Until ($([int]$rest_output.StatusCode) -ne 502 -or $attempt -ge 5) 102 | $data += $rest_output 103 | 104 | } 105 | 106 | End { 107 | Return $data 108 | } 109 | 110 | } 111 | 112 | function Get-AuvikBillingDetails { 113 | [CmdletBinding(DefaultParameterSetName = 'show')] 114 | Param ( 115 | [Parameter(ParameterSetName = 'show')] 116 | [Alias('Tenant')] 117 | [String]$PrimaryTenant, 118 | 119 | [Parameter(ParameterSetName = 'show')] 120 | [String]$QueryTenant, 121 | 122 | [Parameter(ParameterSetName = 'show')] 123 | [ValidateSet('all', 'children')] 124 | [String]$Descendants = '', 125 | 126 | [Parameter(ParameterSetName = 'show')] 127 | [Alias('Date')] 128 | [datetime]$FromDate, 129 | 130 | [Parameter(ParameterSetName = 'show')] 131 | [datetime]$ToDate, 132 | 133 | [Parameter(ParameterSetName = 'show', Mandatory = $false)] 134 | [switch]$Daily=$False 135 | 136 | ) 137 | 138 | Begin { 139 | $data = @() 140 | $qparams = @{} 141 | $x_api_authorization = "$($Auvik_API_Credential.UserName):$([Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Auvik_API_Credential.Password)))" 142 | $x_api_authorization = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($x_api_authorization)) 143 | 144 | If (!($PrimaryTenant)) { 145 | $PrimaryTenant = Get-AuvikTenants | Select-Object -ExpandProperty attributes | Sort-Object -Property @{Expression={$_.tenantType -eq 'multiClient'}; Ascending=$False} | Select-Object -ExpandProperty domainprefix -First 1 146 | } 147 | If (!($PrimaryTenant)) { 148 | Write-Error "Failed to resolve Primary Tenant Name" 149 | } 150 | 151 | If ($PSCmdlet.ParameterSetName -eq 'show') { 152 | If ($QueryTenant) { 153 | $qparams += @{'tenant' = $QueryTenant} 154 | } Else { 155 | $qparams += @{'tenant' = $PrimaryTenant} 156 | } 157 | If ($Descendants) { 158 | $qparams += @{'descendants' = $Descendants} 159 | } 160 | If (!($FromDate)) { 161 | If ($ToDate) { 162 | $FromDate = $ToDate 163 | } Else { 164 | $FromDate=(Get-Date).AddDays(-1) 165 | } 166 | } 167 | $qparams += @{'from' = $FromDate.ToString('yyyy-MM-dd')} 168 | If ($ToDate) { 169 | $qparams += @{'to' = $FromDate.ToString('yyyy-MM-dd')} 170 | } Else { 171 | If ($Daily -eq $True) { 172 | $qparams += @{'to' = ((Get-Date).AddDays(-1)).ToString('yyyy-MM-dd')} 173 | } Else { 174 | $qparams += @{'to' = $FromDate.ToString('yyyy-MM-dd')} 175 | } 176 | } 177 | If ($Null -ne $Daily) { 178 | If ($Daily -eq $True) { 179 | $qparams += @{'daily' = 'true'} 180 | } Else { 181 | $qparams += @{'daily' = 'false'} 182 | } 183 | } 184 | } 185 | Else { 186 | #Unknown Parameter set is selected 187 | } 188 | 189 | } 190 | 191 | Process { 192 | 193 | $resource_uri = ('/api/billing/v1/details') 194 | $x_Base_URI = $Auvik_Base_URI -replace '(?<=//)[^.]+',$PrimaryTenant 195 | 196 | $attempt=0 197 | Do { 198 | $attempt+=1 199 | If ($attempt -gt 1) {Start-Sleep 2} 200 | Write-Debug "Testing $($Auvik_Base_URI + $resource_uri)$(If ($qparams.Count -gt 0) {'?' + $(($qparams.GetEnumerator() | ForEach-Object {"$($_.Name)=$($_.Value)"}) -join '&') })" 201 | $rest_output = try { 202 | $Null = $AuvikAPI_Headers.Add("Authorization", "Basic $x_api_authorization") 203 | Invoke-RestMethod -method 'GET' -uri ($x_Base_URI + $resource_uri) -Headers $AuvikAPI_Headers -Body $qparams -ErrorAction SilentlyContinue 204 | } catch [System.Net.WebException] { 205 | $_.Exception.Response 206 | } catch { 207 | Write-Error $_ 208 | } finally { 209 | $Null = $AuvikAPI_Headers.Remove('Authorization') 210 | } 211 | Write-Verbose "Status Code Returned: $([int]$rest_output.StatusCode)" 212 | } Until ($([int]$rest_output.StatusCode) -ne 502 -or $attempt -ge 5) 213 | $data += $rest_output 214 | 215 | } 216 | 217 | End { 218 | Return $data 219 | } 220 | 221 | } 222 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Auvik-PowerShell-Module 2 | PowerShell Wrapper for the [Auvik API](https://auvikapi.us1.my.auvik.com/docs) 3 | 4 | # Base Module Functions 5 | ### Add-AuvikBaseURI 6 | Description: Set the URI for API access. Will set Base URI to default of https://auvikapi.us1.my.auvik.com if no option is provided. 7 | 8 | Options: [-BaseURI ] 9 | Options: [-DC ] 10 | Options: [-DC ] 11 | #### Example 12 | Set the Base URI to the US2 Datacenter 13 | 14 | Add-AuvikBaseURI -DC US2 15 | 16 | ### Get-AuvikBaseURI 17 | Description: Returns the URI configured for the current session 18 | Options: None 19 | 20 | ### Remove-AuvikBaseURI 21 | Description: Removes the URI from the current session 22 | Options: None 23 | 24 | ### Add-AuvikAPICredential 25 | Description: Sets a credential for use in the current session 26 | 27 | Options: [-UserName ] [-ApiKey ] 28 | 29 | ### Get-AuvikAPICredential 30 | Description: Returns the current session credential object 31 | Options: None 32 | ### Remove-AuvikAPICredential 33 | Description: Removes the credential from the current session 34 | Options: None 35 | 36 | ### Export-AuvikModuleSettings 37 | Description: Stores the current session Module Settings including URI and Credential for later use for the current user only. 38 | Options: None 39 | ### Import-AuvikModuleSettings 40 | Description: Loads previously exported settings. 41 | Options: None 42 | 43 | # Functions by Endpoint 44 | ## Alerts 45 | ### Get-AuvikAlertsInfo 46 | Description: Returns Alerts History 47 | 48 | Options: [-ID ] 49 | Options: [-Tenants ] [-Entities ] 50 | [-AlertSpecificationID ] 51 | [-Severity ] 52 | [-Status ] 53 | [-Dismissed ] 54 | [-Dispatched ] 55 | [-DetectedAfter ] 56 | [-DetectedBefore ] 57 | 58 | ## Billing 59 | ### Get-AuvikBillingInfo 60 | Description: Returns Billing Information 61 | 62 | Options: [-Tenant|PrimaryTenant ] 63 | [-QueryTenant ] [-Descendants ] 64 | [-Date|FromDate ] 65 | [-ToDate ] 66 | [-Daily ] 67 | 68 | ### Get-AuvikBillingDetails 69 | Description: Returns Billing Details 70 | 71 | Options: [-Tenant|PrimaryTenant ] 72 | [-QueryTenant ] [-Descendants ] 73 | [-Date|FromDate ] 74 | [-ToDate ] 75 | [-Daily ] 76 | 77 | ## Component 78 | ### Get-AuvikComponentsInfo 79 | Description: Returns Component Information 80 | 81 | Options: [-ID ] 82 | Options: [-Tenants ] [-Devices ] 83 | [-DeviceName ] 84 | [-CurrentStatus ] 85 | [-ModifiedAfter ] 86 | 87 | ## Configuration 88 | ### Get-AuvikDeviceConfiguration 89 | Description: Returns information on device configurations. 90 | 91 | Options: [-ID ] 92 | Options: [-Tenants ] [-Devices ] 93 | [-BackupTimeAfter ] 94 | [-BackupTimeBefore ] 95 | [-IsRunning ] 96 | 97 | ## Credentials 98 | ### Confirm-AuvikAPICredential 99 | Description: Test the current or provided credential to verify access. Returns the server response or True/False with -Quiet 100 | 101 | Options: [-UserName ] [-ApiKey ] [-Quiet] 102 | Options: [-Credential ] [-Quiet] 103 | 104 | ## Device 105 | ### Get-AuvikDevicesInfo 106 | Description: Returns Device Information 107 | 108 | Options: [-ID ] [-IncludeDetailFields ] 109 | Options: [-Tenants ] [-Networks ] 110 | [-MakeModel ] [-VendorName ] 111 | [-ModifiedAfter ] 112 | [-IncludeDetailFields ] 113 | [-Status ] 114 | [-DeviceType ] 115 | 116 | ### Get-AuvikDevicesDetails 117 | Description: Returns Device Details 118 | 119 | Options: [-ID ] 120 | Options: [-Tenants ] [-ManagedStatus ] 121 | [-SNMPDiscovery ] 122 | [-WMIDiscovery ] 123 | [-LoginDiscovery ] 124 | [-VMWareDiscovery ] 125 | 126 | ### Get-AuvikDevicesExtendedDetails 127 | Description: Returns Extended Device Information. Information varies by Device Type 128 | 129 | Options: [-ID ] 130 | Options: [-Tenants ] [-ModifiedAfter ] 131 | [-DeviceType ] 132 | 133 | ## Entity 134 | ### Get-AuvikEntityAudits 135 | Description: Returns Audit Information 136 | 137 | Options: [-ID ] 138 | Options: [-Tenants ] [-User ] 139 | [-Category ] 140 | [-Status ] 141 | [-ModifiedAfter ] 142 | 143 | ### Get-AuvikEntityNotes 144 | Description: Returns Note Information 145 | 146 | Options: [-ID ] 147 | Options: [-Tenants ] [-Entities ] 148 | [-EntityName ] 149 | [-User ] 150 | [-Type ] 151 | [-ModifiedAfter ] 152 | 153 | ## Interface 154 | ### Get-AuvikInterfacesInfo 155 | Description: Returns Interface Information 156 | 157 | Options: [-ID ] 158 | Options: [-Tenants ] [-Devices ] 159 | [-InterfaceType ] 160 | [-AdminStatus ] 161 | [-OperationalStatus ] 162 | [-ModifiedAfter ] 163 | 164 | ## Meta Data 165 | ### Get-AuvikMetaField 166 | Description: Returns Meta Data Field Information 167 | 168 | Options: -Endpoint -Field 169 | 170 | ## Network 171 | ### Get-AuvikNetworksInfo 172 | Description: Returns Network Information 173 | 174 | Options: [-ID ] [-IncludeDetailFields ] 175 | Options: [-Tenants ] [-Devices ] 176 | [-NetworkType ] 177 | [-IncludeDetailFields ] 178 | [-ScanStatus ] 179 | [-ModifiedAfter ] 180 | 181 | ### Get-AuvikNetworksDetails 182 | Description: Returns Network Details 183 | 184 | Options: [-ID ] 185 | Options: [-Tenants ] [-Devices ] 186 | [-NetworkType ] 187 | [-IncludeDetailFields ] 188 | [-ScanStatus ] 189 | [-Scope ] 190 | [-ModifiedAfter ] 191 | 192 | ## Tenants 193 | ### Get-AuvikTenants 194 | Description: Returns the list of tenant IDs available for the current user 195 | Options: None 196 | 197 | # Example 198 | Return all tenants. Return managed devices for each tenant and return device counts for each type of device. 199 | 200 | Import-Module AuvikAPI 201 | If (Confirm-AuvikAPICredential -Quiet) { 202 | $AuvikTenants = Get-AuvikTenants | Where-Object {$_.attributes.tenantType -eq 'client'} 203 | ForEach ($tenant in $AuvikTenants) { 204 | $TenantDevices = Get-AuvikDevicesInfo -Tenant $tenant.ID -IncludeDetailFields manageStatus 205 | $ManagedDeviceIDs = $TenantDevices | Select-Object -ExpandProperty 'Included' -ErrorAction SilentlyContinue | Where-Object {$_.attributes.manageStatus -eq 'true'} | Select-Object -ExpandProperty 'ID' -ErrorAction SilentlyContinue 206 | $ManagedDevices = $TenantDevices | Select-Object -ExpandProperty 'Data' -ErrorAction SilentlyContinue | Where-Object {$ManagedDeviceIDs -contains $_.ID} 207 | $ManagedDevicesGroup = $ManagedDevices | Select-Object -ExpandProperty Attributes -ErrorAction SilentlyContinue | Group-Object -Property deviceType -AsHashTable -ErrorAction SilentlyContinue 208 | If ($ManagedDevicesGroup) { 209 | Write-Output "Client: $($tenant.attributes.domainPrefix)" 210 | ForEach ($deviceType in $ManagedDevicesGroup.Keys) { 211 | Write-Output "$deviceType,$($ManagedDevicesGroup.$deviceType.Count)" 212 | } 213 | } 214 | } 215 | } 216 | 217 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /AuvikAPI/Resources/Device.ps1: -------------------------------------------------------------------------------- 1 | function Get-AuvikDevicesInfo { 2 | [CmdletBinding(DefaultParameterSetName = 'index')] 3 | Param ( 4 | [Parameter(ParameterSetName = 'show')] 5 | [String[]]$Id, 6 | 7 | [Parameter(ParameterSetName = 'index')] 8 | [String[]]$Networks = '', 9 | 10 | [Parameter(ParameterSetName = 'index')] 11 | [ValidateSet('unknown', 'switch', 'l3Switch', 'router', ` 12 | 'accessPoint', 'firewall', 'workstation', 'server', 'storage', ` 13 | 'printer', 'copier', 'hypervisor', 'multimedia', 'phone', ` 14 | 'tablet', 'handheld', 'virtualAppliance', 'bridge', ` 15 | 'controller', 'hub', 'modem', 'ups', 'module', 'loadBalancer', ` 16 | 'camera', 'telecommunications', 'packetProcessor', 'chassis', ` 17 | 'airConditioner', 'virtualMachine', 'pdu', 'ipPhone', ` 18 | 'backhaul', 'internetOfThings', 'voipSwitch', 'stack', ` 19 | 'backupDevice', 'timeClock', 'lightingDevice', 'audioVisual', ` 20 | 'securityAppliance', 'utm', 'alarm', 'buildingManagement', ` 21 | 'ipmi', 'thinAccessPoint', 'thinClient')] 22 | [String]$DeviceType = '', 23 | 24 | [Parameter(ParameterSetName = 'index')] 25 | [String]$MakeModel = '', 26 | 27 | [Parameter(ParameterSetName = 'index')] 28 | [String]$VendorName = '', 29 | 30 | [Parameter(ParameterSetName = 'index')] 31 | [ValidateSet('online', 'offline', 'unreachable', 'testing', ` 32 | 'unknown', 'dormant', 'notPresent', 'lowerLayerDown')] 33 | [String]$Status = '', 34 | 35 | [Parameter(ParameterSetName = 'index')] 36 | [datetime]$ModifiedAfter, 37 | 38 | [Parameter(ParameterSetName = 'index')] 39 | [String[]]$Tenants = '', 40 | 41 | [Parameter(ParameterSetName = 'show')] 42 | [Parameter(ParameterSetName = 'index')] 43 | [ValidateSet('discoveryStatus', 'components', 'connectedDevices', ` 44 | 'configurations', 'manageStatus', 'interfaces')] 45 | [String[]]$IncludeDetailFields = '' 46 | 47 | ) 48 | 49 | Begin { 50 | $data = @() 51 | $qparams = @{} 52 | $x_api_authorization = "$($Auvik_API_Credential.UserName):$([Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Auvik_API_Credential.Password)))" 53 | $x_api_authorization = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($x_api_authorization)) 54 | } 55 | 56 | Process { 57 | If ($IncludeDetailFields) { 58 | $qparams += @{'include' = 'deviceDetail'; 'fields[deviceDetail]' = $IncludeDetailFields -join ','} 59 | } 60 | 61 | If ($PSCmdlet.ParameterSetName -eq 'index') { 62 | $Id = @('') 63 | If ($Tenants) { 64 | $qparams += @{'tenants' = $Tenants -join ','} 65 | } 66 | If ($DeviceType) { 67 | $qparams += @{'filter[deviceType]' = $DeviceType} 68 | } 69 | If ($Networks) { 70 | $qparams += @{'filter[networks]' = $Networks -join ','} 71 | } 72 | If ($MakeModel) { 73 | $qparams += @{'filter[makeModel]' = "`"$MakeModel`""} 74 | } 75 | If ($VendorName) { 76 | $qparams += @{'filter[vendorName]' = "`"$VendorName`""} 77 | } 78 | If ($Status) { 79 | $qparams += @{'filter[onlineStatus]' = $Status} 80 | } 81 | If ($ModifiedAfter) { 82 | $qparams += @{'filter[modifiedAfter]' = $ModifiedAfter.ToString('yyyy-MM-ddTHH:mm:ss.fffzzz')} 83 | } 84 | } 85 | Else { 86 | #Parameter set "Show" is selected 87 | } 88 | 89 | ForEach ($deviceId IN $Id) { 90 | $resource_uri = ('/v1/inventory/device/info') 91 | $qparams['page[first]'] = 100 92 | If (!($Null -eq $deviceId) -and $deviceId -gt '') { 93 | $resource_uri = ('/v1/inventory/device/info/{0}' -f $deviceId) 94 | $Null = $qparams.Remove('page[first]') 95 | } 96 | 97 | Do { 98 | $attempt=0 99 | Do { 100 | $attempt+=1 101 | If ($attempt -gt 1) {Start-Sleep 2} 102 | Write-Debug "Testing $($Auvik_Base_URI + $resource_uri)$(If ($qparams.Count -gt 0) {'?' + $(($qparams.GetEnumerator() | ForEach-Object {"$($_.Name)=$($_.Value)"}) -join '&') })" 103 | $rest_output = try { 104 | $Null = $AuvikAPI_Headers.Add("Authorization", "Basic $x_api_authorization") 105 | Invoke-RestMethod -method 'GET' -uri ($Auvik_Base_URI + $resource_uri) -Headers $AuvikAPI_Headers -Body $qparams -ErrorAction SilentlyContinue 106 | } catch [System.Net.WebException] { 107 | $_.Exception.Response 108 | } catch { 109 | Write-Error $_ 110 | } finally { 111 | $Null = $AuvikAPI_Headers.Remove('Authorization') 112 | } 113 | Write-Verbose "Status Codes Returned: $([int]$rest_output.StatusCode)" 114 | } Until ($([int]$rest_output.StatusCode) -ne 502 -or $attempt -ge 5) 115 | $data += $rest_output 116 | If ($rest_output.links.next) {$qparams['page[after]'] = $rest_output.links.next -replace '%..','' -replace '.*?pageafter=([^&]*).*',"`$1"} 117 | } Until (!($rest_output.links.next) -or $rest_output.links.next -eq '' ) 118 | } 119 | } 120 | 121 | End { 122 | Return $data 123 | } 124 | 125 | } 126 | 127 | 128 | function Get-AuvikDevicesDetails { 129 | [CmdletBinding(DefaultParameterSetName = 'index')] 130 | Param ( 131 | [Parameter(ParameterSetName = 'show')] 132 | [String[]]$Id, 133 | 134 | [Parameter(ParameterSetName = 'index')] 135 | [ValidateSet('disabled', 'determining', 'notSupported', ` 136 | 'notAuthorized', 'authorizing', 'authorized', 'privileged')] 137 | [String]$SNMPDiscovery = '', 138 | 139 | [Parameter(ParameterSetName = 'index')] 140 | [ValidateSet('disabled', 'determining', 'notSupported', ` 141 | 'notAuthorized', 'authorizing', 'authorized', 'privileged')] 142 | [String]$WMIDiscovery = '', 143 | 144 | [Parameter(ParameterSetName = 'index')] 145 | [ValidateSet('disabled', 'determining', 'notSupported', ` 146 | 'notAuthorized', 'authorizing', 'authorized', 'privileged')] 147 | [String]$LoginDiscovery = '', 148 | 149 | [Parameter(ParameterSetName = 'index')] 150 | [ValidateSet('disabled', 'determining', 'notSupported', ` 151 | 'notAuthorized', 'authorizing', 'authorized', 'privileged')] 152 | [String]$VMWareDiscovery = '', 153 | 154 | [Parameter(ParameterSetName = 'index')] 155 | [String[]]$Tenants = '', 156 | 157 | [Parameter(ParameterSetName = 'index')] 158 | [Nullable[Boolean]]$ManagedStatus 159 | ) 160 | 161 | Begin { 162 | $data = @() 163 | $qparams = @{} 164 | $x_api_authorization = "$($Auvik_API_Credential.UserName):$([Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Auvik_API_Credential.Password)))" 165 | $x_api_authorization = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($x_api_authorization)) 166 | } 167 | 168 | Process { 169 | 170 | If ($PSCmdlet.ParameterSetName -eq 'index') { 171 | $Id = @('') 172 | If ($Tenants) { 173 | $qparams += @{'tenants' = $Tenants -join ','} 174 | } 175 | If ($SNMPDiscovery) { 176 | $qparams += @{'filter[discoverySNMP]' = $SNMPDiscovery} 177 | } 178 | If ($WMIDiscovery) { 179 | $qparams += @{'filter[discoveryWMI]' = $WMIDiscovery} 180 | } 181 | If ($LoginDiscovery) { 182 | $qparams += @{'filter[discoveryLogin]' = $LoginDiscovery} 183 | } 184 | If ($VMWareDiscovery) { 185 | $qparams += @{'filter[discoveryVMWare]' = $VMWareDiscovery} 186 | } 187 | If ($Null -ne $ManagedStatus) { 188 | If ($ManagedStatus -eq $True) { 189 | $qparams += @{'filter[managedStatus]' = 'true'} 190 | } Else { 191 | $qparams += @{'filter[managedStatus]' = 'false'} 192 | } 193 | } 194 | } 195 | Else { 196 | #Parameter set "Show" is selected 197 | } 198 | 199 | ForEach ($deviceId IN $Id) { 200 | $resource_uri = ('/v1/inventory/device/detail') 201 | If (!($Null -eq $deviceId) -and $deviceId -gt '') { 202 | $resource_uri = ('/v1/inventory/device/detail/{0}' -f $deviceId) 203 | } 204 | 205 | $attempt=0 206 | Do { 207 | $attempt+=1 208 | If ($attempt -gt 1) {Start-Sleep 2} 209 | Write-Debug "Testing $($Auvik_Base_URI + $resource_uri)$(If ($qparams.Count -gt 0) {'?' + $(($qparams.GetEnumerator() | ForEach-Object {"$($_.Name)=$($_.Value)"}) -join '&') })" 210 | $rest_output = try { 211 | $Null = $AuvikAPI_Headers.Add("Authorization", "Basic $x_api_authorization") 212 | Invoke-RestMethod -method 'GET' -uri ($Auvik_Base_URI + $resource_uri) -Headers $AuvikAPI_Headers -Body $qparams -ErrorAction SilentlyContinue 213 | } catch [System.Net.WebException] { 214 | $_.Exception.Response 215 | } catch { 216 | Write-Error $_ 217 | } finally { 218 | $Null = $AuvikAPI_Headers.Remove('Authorization') 219 | } 220 | Write-Verbose "Status Code Returned: $([int]$rest_output.StatusCode)" 221 | } Until ($([int]$rest_output.StatusCode) -ne 502 -or $attempt -ge 5) 222 | $data += $rest_output 223 | } 224 | } 225 | 226 | End { 227 | Return $data 228 | } 229 | 230 | } 231 | 232 | function Get-AuvikDevicesExtendedDetails { 233 | [CmdletBinding(DefaultParameterSetName = 'index')] 234 | Param ( 235 | [Parameter(ParameterSetName = 'show')] 236 | [String]$Id, 237 | 238 | [Parameter(ParameterSetName = 'index', Mandatory=$True)] 239 | [ValidateSet('unknown', 'switch', 'l3Switch', 'router', ` 240 | 'accessPoint', 'firewall', 'workstation', 'server', 'storage', ` 241 | 'printer', 'copier', 'hypervisor', 'multimedia', 'phone', ` 242 | 'tablet', 'handheld', 'virtualAppliance', 'bridge', ` 243 | 'controller', 'hub', 'modem', 'ups', 'module', 'loadBalancer', ` 244 | 'camera', 'telecommunications', 'packetProcessor', 'chassis', ` 245 | 'airConditioner', 'virtualMachine', 'pdu', 'ipPhone', ` 246 | 'backhaul', 'internetOfThings', 'voipSwitch', 'stack', ` 247 | 'backupDevice', 'timeClock', 'lightingDevice', 'audioVisual', ` 248 | 'securityAppliance', 'utm', 'alarm', 'buildingManagement', ` 249 | 'ipmi', 'thinAccessPoint', 'thinClient')] 250 | [String]$DeviceType = '', 251 | 252 | [Parameter(ParameterSetName = 'index')] 253 | [datetime]$ModifiedAfter, 254 | 255 | [Parameter(ParameterSetName = 'index')] 256 | [String[]]$Tenants = '' 257 | 258 | ) 259 | 260 | Begin { 261 | $data = @() 262 | $qparams = @{} 263 | $x_api_authorization = "$($Auvik_API_Credential.UserName):$([Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Auvik_API_Credential.Password)))" 264 | $x_api_authorization = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($x_api_authorization)) 265 | } 266 | 267 | Process { 268 | 269 | If ($PSCmdlet.ParameterSetName -eq 'index') { 270 | $Id = @('') 271 | If ($Tenants) { 272 | $qparams += @{'tenants' = $Tenants -join ','} 273 | } 274 | If ($DeviceType) { 275 | $qparams += @{'filter[deviceType]' = $DeviceType} 276 | } 277 | If ($ModifiedAfter) { 278 | $qparams += @{'filter[modifiedAfter]' = $ModifiedAfter.ToString('yyyy-MM-ddTHH:mm:ss.fffzzz')} 279 | } 280 | } 281 | Else { 282 | #Parameter set "Show" is selected 283 | } 284 | 285 | ForEach ($deviceId IN $Id) { 286 | $resource_uri = ('/v1/inventory/device/detail/extended') 287 | If (!($Null -eq $deviceId) -and $deviceId -gt '') { 288 | $resource_uri = ('/v1/inventory/device/detail/extended/{0}' -f $deviceId) 289 | } 290 | 291 | $attempt=0 292 | Do { 293 | $attempt+=1 294 | If ($attempt -gt 1) {Start-Sleep 2} 295 | Write-Debug "Testing $($Auvik_Base_URI + $resource_uri)$(If ($qparams.Count -gt 0) {'?' + $(($qparams.GetEnumerator() | ForEach-Object {"$($_.Name)=$($_.Value)"}) -join '&') })" 296 | $rest_output = try { 297 | $Null = $AuvikAPI_Headers.Add("Authorization", "Basic $x_api_authorization") 298 | Invoke-RestMethod -method 'GET' -uri ($Auvik_Base_URI + $resource_uri) -Headers $AuvikAPI_Headers -Body $qparams -ErrorAction SilentlyContinue 299 | } catch [System.Net.WebException] { 300 | $_.Exception.Response 301 | } catch { 302 | Write-Error $_ 303 | } finally { 304 | $Null = $AuvikAPI_Headers.Remove('Authorization') 305 | } 306 | Write-Verbose "Status Code Returned: $([int]$rest_output.StatusCode)" 307 | } Until ($([int]$rest_output.StatusCode) -ne 502 -or $attempt -ge 5) 308 | $data += $rest_output 309 | } 310 | } 311 | 312 | End { 313 | Return $data 314 | } 315 | 316 | } 317 | --------------------------------------------------------------------------------