functions/Get-EssbaseDatabase.ps1
<#
.SYNOPSIS Get a list of databases from a specified application. .DESCRIPTION Get a list of databases from a specified application. .PARAMETER RestURL <string> The base URL for the REST API interface. Example: 'https://your.domain.com/essbase/rest/v1' .PARAMETER Application <string[]> String Array value of the Application name for which to get a list of databases. Accepts value from Pipeline. .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 System.String[] .OUTPUTS System.Object .EXAMPLE Get-EssbaseDatabase -RestURL 'https://your.domain.com/essbase/rest/v1' -Application 'Test1' -WebSession $MyWebSession .EXAMPLE 'Test1', 'Test2' | Get-EssbaseDatabase -RestURL 'https://your.domain.com/essbase/rest/v1' -Credential $MyCredentials .NOTES Created by : Shayne Scovill .LINK https://github.com/Shayne55434/RESTBase #> function Get-EssbaseDatabase { [CmdletBinding()] param( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$RestURL, [Parameter(Mandatory, ValueFromPipeline)] [ValidateNotNullOrEmpty()] [string[]]$Application, [Parameter()] [ValidateNotNullOrEmpty()] [string]$Database, [Parameter(Mandatory, ParameterSetName='WebSession')] [ValidateNotNullOrEmpty()] [Microsoft.PowerShell.Commands.WebRequestSession]$WebSession, [Parameter(Mandatory, ParameterSetName='Credential')] [ValidateNotNullOrEmpty()] [pscredential]$Credential, [Parameter(Mandatory, ParameterSetName='Username')] [ValidateNotNullOrEmpty()] [string]$Username ) begin { # Decipher which authentication type is being used [hashtable]$htbAuthentication = @{} if ($Credential) { $htbAuthentication.Add('Credential', $Credential) Write-Verbose 'Using provided credentials.' } elseif ($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.' } $arrDatabases = @() } process { foreach ($app in $Application) { $URI = "$RestURL/applications/$($app)/databases/$($Database)" [hashtable]$htbInvokeParameters = @{ Method = 'Get' Uri = $URI ContentType = 'Application/JSON' Headers = @{ accept = 'Application/JSON' } } + $htbAuthentication try { Write-Verbose "Getting databases for '$app'." $results = Invoke-RestMethod @htbInvokeParameters $arrDatabases += $results } catch { Write-Error $($_) } } } end { return $arrDatabases } } |