Updating a Global Variable

Product: PowerShell Universal
Version: 5.0.13

I have a script to get a ServerID and SessionID from our ticketing system. The session id is good for 24 hours so I don’t need to get a new one every time an app loads so I’d like to have a script to run every 24 hours to get a new session id and use that in my app to show some ticket information. This is my script to get the session id

$loginURL = "https://accountname.sysaidit.com/api/v1/login"
$body = @{
    "user_name" = "<username>"
    "password" = "<password>"
}
$jsonBody = $body | ConvertTo-Json

Invoke-RestMethod -Uri $loginURL -Method Post -ContentType "application/json" -Body $jsonBody -SessionVariable Cookie
$sysAidSessionID = $Cookie.Cookies.GetCookies($loginURL)[0].Value
$sysAidServerID = $Cookie.Cookies.GetCookies($loginURL)[1].Value

Set-PSUVariable -Name "sysAidSessionID" -Value $sysAidSessionID -UseDefaultCredentials
Set-PSUVariable -Name "sysAidServerID" -Value $sysAidServerID -UseDefaultCredentials

When I use Set-PSUVariable I get “Parameter set cannot be resolved using the specified named parameters. One or more parameters issued cannot be used together or an insufficient number of parameters were provided.”

When I use $Global:sysAidSessionID = $Cookie.Cookies.GetCookies($loginURL)[0].Value
The variable doesn’t get updated with the new data. I can set it manually it and it works but I would like to automatically get that infromation if possible.

Try it the way how it is displayed in the example:

-------------------------- Example 1 --------------------------
    
    PS C:\> $Variable = Get-UAVariable -Name 'username'
    PS C:\> Set-UAVariable -Variable $Variable -Value 'lee'

First get the var and then set it

Get and Set UAVariable are not found

The term 'Get-UAVariable' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

This ended up working for me

$VariableA = Get-PSUVariable -Name "sysAidSessionID" -TrustCertificate:$true
Set-PSUVariable -Variable $VariableA -Value $sysAidSessionID -TrustCertificate:$true
$VariableB = Get-PSUVariable -Name "sysAidServerID" -TrustCertificate:$true
Set-PSUVariable -Variable $VariableB -Value $sysAidServerID -TrustCertificate:$true