functions/Get-EssbaseApplication.ps1
<#
.SYNOPSIS Get a list of Applications from Essbase. .DESCRIPTION Get a list of Applications from Essbase with the specified visibilty. .PARAMETER RestURL <string> The base URL for the REST API interface. Example: 'https://your.domain.com/essbase/rest/v1' .PARAMETER Visibility <string> ALL shows every application. HIDDEN shows only hidden (Shadow Copy) applications. REGULAR shows all other applications. .PARAMETER WebSession <WebRequestSession> A Web Request Session that contains authentication and header information for the connection. .PARAMETER Credentials <pscredential> PowerShell credentials that contain authentication information for the connection. .INPUTS None .OUTPUTS System.Object .EXAMPLE Get-EssbaseApplications -RestURL 'https://your.domain.com/essbase/rest/v1' -Visibility ALL -WebSession $MyWebSession .EXAMPLE Get-EssbaseApplications -RestURL 'https://your.domain.com/essbase/rest/v1' -Visibility REGULAR -Credential $MyCredentials .NOTES Created by : Shayne Scovill .LINK https://github.com/Shayne55434/RESTBase #> function Get-EssbaseApplication { [CmdletBinding()] Param( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$RestURL, [Parameter(ValueFromPipeline)] [ValidateNotNullOrEmpty()] [string]$Application, [Parameter()] [ValidateNotNullOrEmpty()] [string]$Filter, [Parameter()] [ValidateNotNullOrEmpty()] [int]$Offset, [Parameter()] [ValidateNotNullOrEmpty()] [int]$Limit, [Parameter()] [ValidateNotNullOrEmpty()] [switch]$Links, [Parameter(HelpMessage='ALL shows every application. HIDDEN shows only hidden (Shadow Copy) applications. REGULAR shows all other applications.')] [ValidateSet('ALL', 'HIDDEN', 'REGULAR')] [string]$Visibility, [Parameter(Mandatory, ParameterSetName='WebSession')] [ValidateNotNullOrEmpty()] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory, ParameterSetName='Credential')] [ValidateNotNullOrEmpty()] [pscredential]$Credential, [Parameter(Mandatory, ParameterSetName='Username')] [ValidateNotNullOrEmpty()] [string]$Username ) # Decipher which authentication type is being used [hashtable]$htbAuthentication = @{} if ($null -ne $Credential) { $htbAuthentication.Add('Credential', $Credential) Write-Verbose 'Using provided credentials.' } elseif ($null -ne $WebSession) { $htbAuthentication.Add('WebSession', $WebSession) Write-Verbose 'Using provided Web Session variable.' } else { [pscredential]$Credential = Get-Credential -Message 'Please enter your Essbase password' -UserName $Username $htbAuthentication.Add('Credential', $Credential) Write-Verbose 'Using provided username and password.' } # Create the URI to be used $URI = "$RestURL/applications" $ApplicationResults = $null if ($Application) { $URI += "/$Application" if (-not($Links.IsPresent)) { $URI += '?links=none' } } elseif ($Visibility) { $URI += "/actions/name/$($Visibility)" } else { $URI += '?' if ($Filter) { $URI += '&filter=' + $Filter } if ($Offset) { $URI += '&offset=' + $Offset } if ($Limit) { $URI += '&limit=' +$Limit } if (-not($Links.IsPresent)) { $URI += '&links=none' } } [hashtable]$htbInvokeParameters = @{ Method = 'Get' Uri = $URI Headers = @{ accept = 'Application/JSON' } } + $htbAuthentication try { Write-Verbose "URI: $($URI)." Write-Verbose "Getting a list of applications." $ApplicationResults = Invoke-RestMethod @htbInvokeParameters } catch { Write-Error "Failed to get applications. $($_)" } return $ApplicationResults } |