Public/Invoke-TMActionRequest.ps1


Function Invoke-TMActionRequest {
    <#
    .SYNOPSIS
        This function accepts a TransitionManager Action Request and queues it for execution
 
 
    .NOTES
        Name: Invoke-TMActionRequest
        Author: TransitionManager
        Version: 1.0
        DateCreated: 2021-04-05
 
 
    .EXAMPLE
        Invoke-TMActionRequest -ActionRequestB64 $Base64EncodedActionRequest
 
 
    .LINK
        https://support.transitionmanager.net
    #>


    [CmdletBinding()]
    param(
        [Parameter(
            Mandatory = $false,
            ValueFromPipeline = $true,
            ValueFromPipelineByPropertyName = $true,
            Position = 0
        )]
        [string]  $ActionRequestB64,
        [Parameter(
            Mandatory = $false,
            ValueFromPipeline = $true,
            ValueFromPipelineByPropertyName = $true,
            Position = 1
        )]
        [string]  $ScriptBlockString,
        [Parameter(
            Mandatory = $false,
            ValueFromPipeline = $true,
            ValueFromPipelineByPropertyName = $true,
            Position = 2
        )]
        [pscredential]  $Credential,
        [Parameter(
            Mandatory = $false,
            ValueFromPipeline = $true,
            ValueFromPipelineByPropertyName = $true,
            Position = 3
        )]
        [pscustomobject]$Params

    )

    BEGIN {}

    PROCESS {
        try {

            ## Import the ActionRequest from the B64 encoded argument
            $ActionRequest = Import-TMDActionRequest -FromB64 $ActionRequestB64 -SkipProviderLoad -PassThru

            ## Create a timestamp for the temp file name
            $Timestamp = [Math]::Round((Get-Date).ToFileTime() / 10000)

            ## Write the ActionRequest to the Queue folder
            $TempFileName = Join-Path $userPaths.queue ($Timestamp.ToString() + '.tmdar')
            Export-Clixml -InputObject $ActionRequest -Path $TempFileName

        } catch {
            throw $_
        }
    }


    END {}
}