Get and set cookies

i want to auto fill certain text boxes based on the user that is browsing the dashboard. At that point the user is not logged in, so my idea was to use browser cookies to store that information.

I was in the process of writing custom javascript to solve reading and writing cookies, but i would prefer to have something like Get-UDCookie and Set-UDCookie (it looks like something like this existed in older UD versions)

By the way cookies that i set manually are not available in the $Cookies variable.

Product: PowerShell Universal
Version: 2.10.2
1 Like

i just stumbled over this post having the same problem.
I used Invoke-UDJavaScript to work this out.
In my case I used a Cookie to store some information permanently.

set Cookie

Invoke-UDJavaScript "
// Build the expiration date string:
var expiration_date = new Date();
var cookie_string = '';
expiration_date.setFullYear(expiration_date.getFullYear() + 1);
// Build the set-cookie string:
cookie_string = 'dashboard_cookie=test; path=/; expires=' + expiration_date.toUTCString();
// Create or update the cookie:
document.cookie = cookie_string;"

unset Cookie

Invoke-UDJavaScript "                                    
var cookie_string = 'dashboard_cookie=;expires=Thu, 01 Jan 1970 00:00:00 UTC;path=/;';            
document.cookie = cookie_string;"

check/read Cookie
You can read the cookies with the integrated PSU variable $Cookies

if ($Cookies.dashboard_cookie -ne $null){
     Write-Host $Cookies.dashboard_cookie


1 Like

Thank you so much. I have just integrated this and it works perfectly. In my case, it saves my users a lot of typing because several forms are pre-populated with cookie data.