public/Get-VPASIncomingRequestDetails.ps1
<#
.Synopsis GET INCOMING REQUEST DETAILS CREATED BY: Vadim Melamed, EMAIL: vmelamed5@gmail.com .DESCRIPTION USE THIS FUNCTION TO GET THE DETAILS OF AN EXISTING INCOMING REQUEST .PARAMETER token HashTable of data containing various pieces of login information (PVWA, LoginToken, HeaderType, etc). If -token is not passed, function will use last known hashtable generated by New-VPASToken .PARAMETER RequestedSafe Safe name that will be used to query for the target account if no AcctID is passed .PARAMETER RequestedUsername Username that will be used to query for the target account if no AcctID is passed .PARAMETER RequestedPlatform PlatformID that will be used to query for the target account if no AcctID is passed .PARAMETER RequestedAddress Address that will be used to query for the target account if no AcctID is passed .PARAMETER RequestedAcctID Unique ID that maps to a single account, passing this variable will skip query functions to find target account .PARAMETER RequestedReason Reason that will be used to query and find the target account request .PARAMETER requestID Unique ID that maps to a single incoming request, passing this variable will skip any query functions .EXAMPLE $IncomingRequestDetailsJSON = Get-VPASIncomingRequestDetails -RequestedUsername {USERNAME VALUE} -RequestedReason {REASON VALUE} .EXAMPLE $IncomingRequestDetailsJSON = Get-VPASIncomingRequestDetails -requestID {REQUESTID VALUE} .OUTPUTS JSON Object (IncomingRequestDetails) if successful $false if failed #> function Get-VPASIncomingRequestDetails{ [OutputType('System.Object',[bool])] [CmdletBinding()] Param( [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true,Position=0)] [String]$RequestedSafe, [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true,Position=1)] [String]$RequestedPlatform, [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true,Position=2)] [String]$RequestedUsername, [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true,Position=3)] [String]$RequestedAddress, [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true,Position=4)] [String]$RequestedAcctID, [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true,Position=5)] [String]$RequestedReason, [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true,Position=6)] [String]$requestID, [Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true,Position=7)] [hashtable]$token ) Begin{ $tokenval,$sessionval,$PVWA,$Header,$ISPSS,$IdentityURL,$EnableTextRecorder,$AuditTimeStamp,$NoSSL,$VaultVersion,$HideWarnings,$AuthenticatedAs,$SubDomain = Get-VPASSession -token $token $CommandName = $MyInvocation.MyCommand.Name $log = Write-VPASTextRecorder -inputval $CommandName -token $token -LogType COMMAND } Process{ Write-Verbose "SUCCESSFULLY PARSED PVWA VALUE" Write-Verbose "SUCCESSFULLY PARSED TOKEN VALUE" try{ if([String]::IsNullOrEmpty($requestID)){ Write-Verbose "NO REQUEST ID PROVIDED...INVOKING HELPER FUNCTION TO RETRIEVE UNIQUE INCOMING REQUEST ID BASED ON SPECIFIED PARAMETERS" [String[]]$requestID = Get-VPASIncomingRequestIDHelper -AcctID $RequestedAcctID -token $token -UserReason $RequestedReason -Safe $RequestedSafe -Username $RequestedUsername -Address $RequestedAddress -Platform $RequestedPlatform } $outputset = @{} foreach($rec in $requestID){ Write-Verbose "RETRIEVING DETAILS FOR requestID: $rec" if($NoSSL){ $uri = "http://$PVWA/PasswordVault/API/incomingrequests/$rec" } else{ $uri = "https://$PVWA/PasswordVault/API/incomingrequests/$rec" } $log = Write-VPASTextRecorder -inputval $uri -token $token -LogType URI $log = Write-VPASTextRecorder -inputval "GET" -token $token -LogType METHOD if($sessionval){ $response = Invoke-RestMethod -Headers @{"Authorization"=$Header} -Uri $uri -Method GET -ContentType "application/json" -WebSession $sessionval } else{ $response = Invoke-RestMethod -Headers @{"Authorization"=$Header} -Uri $uri -Method GET -ContentType "application/json" } $outputlog = $response $log = Write-VPASTextRecorder -inputval $outputlog -token $token -LogType RETURN $outputset += @{ $rec = $response } } Write-Verbose "SUCCESSFULLY RETRIEVED INCOMING REQUEST DETAILS" Write-Verbose "RETURNING JSON OBJECT" return $outputset }catch{ $log = Write-VPASTextRecorder -inputval $_ -token $token -LogType ERROR $log = Write-VPASTextRecorder -inputval "REST API COMMAND RETURNED: FALSE" -token $token -LogType MISC Write-Verbose "UNABLE TO RETRIEVE INCOMING REQUEST DETAILS" Write-VPASOutput -str $_ -type E return $false } } End{ $log = Write-VPASTextRecorder -inputval $CommandName -token $token -LogType DIVIDER } } |