Variable issue in dashboard?

Hello, I developed a web interface to query computers and retrieve information (performance, service, process, installed application, event log, user connected …).
The first page of the dashboard, I ask to enter the name of the computer that I put in a $cache:computer variable to be able to query it.
once the user 1 validates, he will be redirected to the computer page to display the information, then the user has the possibility to click on the performance page to see the state of the processor and memory of the computer.
I have a problem with the computer variable, indeed:
If user 1 validates computer 1, he will have the information of computer 1 in the computer page.
if a user 2 validates a computer 2 he will have the information on computer 2.
but if user 1 wants to go to the performance page or just update the computer page it will have the info of computer 2.

how can we solve this problem so that the computer variable remains for each user session.
FYI: I hosted the dashboard on an IIS server.
Thank you.

$Cache: is globally available, to all visitors

$Session:computer should do the trick

I used the variable $session:computer but the variable is not recognized in all endpoints and other pages.
Session variable has a same scope of cache variable?

ah, it needs to be available only for one user, but across different endpoints/runspaces etc.

Havent run into that usecase. there are other scope modifiers that you can try.
about Scopes - PowerShell | Microsoft Docs

You could create global cache variable using the $user variable in the name to create something unique to that user?

New-Variable -name "$($User)_Computer" -Value @{} -scrope Global

or something like that maybe.

I created the dashboard to be used by IT support technicians.
they add the name of the station in the home page then it validates, then they will be redirected to the desktop page which will display computer information.
my problem is that the computer variable resets each time a technician validates the home page, for example:

  • technician 1 enters the name of computer1 and validates, it is redirected to the computer page with computer1 information
  • if a technician 2 enters the name of computer 2 and validates, he is redirected to the computer page with the information of computer 2

my problem : if the technician 1 decides to refresh the computer page or open another page he will have the information of computer2 and not computer1.

sorry i think this is a complicated problem :sob:

thank you

Yeah, thats how $cache:computer would work.
The content of $cache: variables will be the same for all users. any chance will affect everyone.

You may able to get around that using variables with dynamic names based on the user as I mentioned, so that the variable is unique to the visiting users.

Alternatively you could troubleshoot why $session variables isnt working for you, because it should, or maybe design your pages/dashboards and API to use variable URLS.
Endpoints - PowerShell Universal


I ressolved the issue : i used the session variable and -EndpointInitialization to use variable in all endpoint.

Thank yo for your help.

If you want I’m interested of the code for event log if you can post it on GitHub or similar?

I have done functions for almost everything else so I can share some to you also.
I have the service, autostrat, process, delete / see user profiles etc