Menu

Invoke-SasAsync

Andreas Menrath
Synopsis
    Run powershell commandlets as an asynchronous task

Syntax
    Invoke-SasAsync [-SasInput] <Object[]> [-ScriptBlock] <ScriptBlock> [<CommonParameters>]

Description
    This function allows you to execute a script block with a SAS object in a background task.

Parameters
    -SasInput <Object[]>
        The SAS object(s) you want to use inside your custom script block. May be of type SAS.Workspace or SASOMI.IOMI

        Required?                    true
        Position?                    1
        Default value                
        Accept pipeline input?       false
        Accept wildcard characters?  false

    -ScriptBlock <ScriptBlock>
        A custom script block with Cmdlets4Sas and other powershell instructions. 
        NOTE: You can reference your SasObject with the $SasInput variable.

        Required?                    true
        Position?                    2
        Default value                
        Accept pipeline input?       false
        Accept wildcard characters?  false

Notes
    The SAS object you provide as parameter can be used inside your scriptblock as the variable $SasInput.
    If you want to use some results from the background task you must save them in a variable named $SasOutput

Examples
    -------------------------- EXAMPLE 1 --------------------------
    C:\PS>$sb = [scriptblock] {$clone = Copy-SasWorkspace $SasInput; Invoke-SasCode $clone "data _null_; run;"; Disconnect-SasServer $clone;}

    $job  = Invoke-SasAsync $workspace $sb

    -------------------------- EXAMPLE 2 --------------------------
    C:\PS>$ws = Connect-SasWorkspaceLocal

    $ScriptBlock = [scriptblock]{
                             $clone = Copy-SasWorkspace $SasInput; 
                             Invoke-SasCode $clone "data _null_; call sleep(10,1); run;";
                             # write data to console 
                             Read-SasData $clone "sashelp.class";
                             # save results in hashtable 
                             $SasOutput = @{};
                             $SasOutput["log"] = Read-SasLog $clone; 
                             $SasOutput["data"] = Read-SasData $clone "sashelp.class"; 
                             Disconnect-SasServer $clone; 
                            }
$job  = Invoke-SasAsync $ws $ScriptBlock
$job | Get-SasAsyncResult # writes to console

# use results from background job
$job.SasOutput["log"]
$job.SasOutput["data"]
Disconnect-SasServer $ws

Related

Wiki: Home

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.