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.