mpulse/Get-mPulseSecurityToken.ps1
function Get-mPulseSecurityToken { Param( [Parameter(Mandatory=$false, ParameterSetName='userpass')] [string] $Username, [Parameter(Mandatory=$false, ParameterSetName='userpass')] [string] $Password, [Parameter(Mandatory=$false, ParameterSetName='apitoken')] [string] $ApiToken, [Parameter(Mandatory=$false, ParameterSetName='apitoken')] [string] $Tenant ) $RequestURL = 'https://mpulse.soasta.com/concerto/services/rest/RepositoryService/v1/Tokens' $Headers = @{ 'Content-Type' = 'application/json' } if($PSCmdlet.ParameterSetName -eq 'userpass'){ $BodyObj = @{ username = $Username password = $Password } } elseif($PSCmdlet.ParameterSetName -eq 'apitoken'){ $BodyObj = @{ apiToken = $ApiToken } if($Tenant){ $BodyObj['tenant'] = $Tenant } } $Body = $BodyObj | ConvertTo-Json -Depth 100 try { if($env:https_proxy){ $Result = Invoke-RestMethod -Method PUT -Uri $RequestURL -Headers $Headers -Body $Body -proxy $env:https_proxy } else{ $Result = Invoke-RestMethod -Method PUT -Uri $RequestURL -Headers $Headers -Body $Body } return $Result } catch { throw $_.Exception } } |