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
   If successful:
   {
        "VPASRequestSafe_20": {
                                   "RequestorFullName": "vadim",
                                   "RequestID": "VPASRequestSafe_20",
                                   "SafeName": "VPASRequestSafe",
                                   "RequestorUserName": "vadim@vman.com",
                                   "RequestorReason": "(ConnectionClient=PSM-RDP) Testing Account Request",
                                   "UserReason": "Testing Account Request",
                                   "CreationDate": 1724125545,
                                   "Operation": "Connect to VPASDualControl-DomainAdmin011-vman.com",
                                   "ExpirationDate": 1726717545,
                                   "OperationType": 4,
                                   "AccessType": "ManyTimes",
                                   "ConfirmationsLeft": 1,
                                   "AccessFrom": 1724158800,
                                   "AccessTo": 1724173200,
                                   "Status": 1,
                                   "StatusTitle": "Waiting: 1 more user(s) must confirm the request",
                                   "InvalidRequestReason": 0,
                                   "CurrentConfirmationLevel": 1,
                                   "RequiredConfirmersCountLevel2": 1,
                                   "TicketingSystemProperties": {
                                                                     "Name": null,
                                                                     "Number": null,
                                                                     "Status": null
                                                                 },
                                   "AdditionalInfo": {
 
                                                      },
                                   "AccountDetails": {
                                                          "AccountID": "120_3",
                                                          "Properties": "@{Address=vman.com; Safe=VPASRequestSafe; Folder=Root; Name=Operating System-VPASDualControl-vman.com-DomainAdmin01; PolicyID=VPASDualControl; PlatformName=VPASDualControl; DeviceType=Operating System; LastModifiedDate=1715222718000; LastModifiedBy=vadim@vman.com; LastUsedDate=1715222731000; LastUsedBy=vadim@vman.com; UserName=DomainAdmin011; LockedBy=; CPMDisabled=; CPMStatus=NoAction; ManagedByCPM=True; DeletedBy=; DeletionDate=0; ImmediateCPMTask=NoTask; LastCPMTask=NoTask; CreationDate=1715222718; IsSSHKey=False; IsIrregularPlatform=False; CreationMethod=PVWA}"
                                                      },
                                   "Confirmers": [
                                                      "@{Type=1; ID=41; Name=vadim@vman.com; Action=2; Reason=; ActionDate=0; AdditionalDetails=; Members=}"
                                                  ]
                               }
   }
   ---
   $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
    }
}