Functions/Authentication/Use-PASSession.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function Use-PASSession {
    <#
    .SYNOPSIS
    Sets module scope variables allowing saved session information to be used for future requests.

    .DESCRIPTION
    Use session data (BaseURI, ExternalVersion, WebSession (containing Authorization Header)) for future requests.
    psPAS uses variables in the Module scope to provide required values to all module functions, use this function to
    set the required values in the module scope, using session information returned from `Get-PASSession`.

    .PARAMETER Session
    An object containing psPAS session data, as returned from Get-PASSession

    .EXAMPLE
    Use Saved Session Data for future requests

    Use-PASSession -Session $Session

    .EXAMPLE
    Save current session, switch to using different session details, switch back to original session.

    $CurrentSession = Get-PASSession

    Use-PASSession -Session $OtherSession
    ...
    Use-PASSession -Session $CurrentSession

    #>

    [CmdletBinding()]
    param(
        [parameter(
            Mandatory = $true,
            ValueFromPipeline = $true
        )]
        [psTypeName('psPAS.CyberArk.Vault.Session')]$Session

    )

    BEGIN { }#begin

    PROCESS {

        Set-Variable -Name BaseURI -Value $Session.BaseURI -Scope Script
        Set-Variable -Name ExternalVersion -Value $Session.ExternalVersion -Scope Script
        Set-Variable -Name WebSession -Value $Session.WebSession -Scope Script

    }#process

    END { }#end

}