functions/Get-EssbaseFile.ps1
<#
.SYNOPSIS List all files from a specified application and database. .DESCRIPTION List all files from a specified application and database. .PARAMETER RestURL <string> The base URL for the REST API interface. Example: 'https://your.domain.com/essbase/rest/v1' .PARAMETER Application <string> String value of the Application name for which to get a list of files. .PARAMETER Database <string> String value of the Database name for which to get a list of files. .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-EssbaseFile -RestURL 'https://your.domain.com/essbase/rest/v1' -Application 'Test1' -Database 'MyDB' -WebSession $MyWebsession .EXAMPLE Get-EssbaseFile -RestURL 'https://your.domain.com/essbase/rest/v1' -Application 'Test1' -Database 'MyDB'' -Credential $MyCredentials .NOTES Created by : Shayne Scovill .LINK https://github.com/Shayne55434/RESTBase #> function Get-EssbaseFile { [CmdletBinding()] param( [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$RestURL, [Parameter(Mandatory)] [ValidateNotNullOrEmpty()] [string]$Application, [Parameter(Mandatory)] [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 ) # 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.' } [hashtable]$htbInvokeParameters = @{ Method = 'Get' Uri = "$RestURL/files/applications/$($Application)/$($Database)" Headers = @{ accept = 'Application/JSON' } } + $htbAuthentication try{ Write-Verbose "Getting a list of files from '$Application.$Database'." [object]$objFiles = Invoke-RestMethod @htbInvokeParameters } catch { Write-Error "Failed to get a list of items. $($_)" } return $objFiles } |