I have a dashboard with buttons. Once a button is clicked, a ps1 script is called and executed successfully. How can I structure my dashboard so that when a button is clicked, a new PowerShell Window will open and output the results to the console during script execution?
Not sure if this is what you are looking or the answer to your issue/question but I got mine to work by creating an Identity under Security, then create and assign new Token to newly created Identity. Then use the token key to connect to the PSUServer and then call UAScript. Example code below of how is use it. My example below will display on-demand output from the running script into a code editor element.
Thanks @adam and @irortiz, I think I’m close. I am now able to execute the .ps1 when clicking the button on the dashboard. I can see the output while logged into the management console of PowerShellUniversal and navigating to Automation > Jobs > output. Am I still missing something to get this output to be displayed on the screen in real-time when the user clicks the button?
I’m getting an error stating that the ‘New-UDCodeEditor’ is not recognized as the name of a cmdlet even though I have the UniversalDashboard.CodeEditor module installed. I’ll squash that error and post the results once I figure that out. This definitely places me further along! Thanks!
Correct @irortiz, I’ve confirmed that the UniversalDashboard.CodeEditor component has always been there and it shows up when running “Get-Module” in PowerShell so I’m not sure why the command is still not recognized. Still troubleshooting.
@adam, any thought why I am still receiving the following error message although the CodeEditor module is showing up under Components on the admin page (like the screenshot @irortiz posted) as well as showing as installed in VSCode? The line I’m having issues with is “New-UDCodeEditor -Id ‘codeEditor’ -ReadOnly -Height 500” as you used in Get the output from script "live" in dashboard? - #14 by adam
The term “New-UDCodeEditor” is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Figured it out! Although the path to the components show C:\ProgramData\PowerShellUniversal\Dashboard\Components and I confirmed that the module was in that location, it wasn’t until I added the module to “C:\Program Files\WindowsPowerShell\Modules” that the code editor started working in the dashboard and the cmdlet was recognized.
I’m still figuring out what the essential locations are as far as where I need to store the modules in order for them to work properly, but that is for another discussion.
Final look of the completed, working script. Once the “Apply Update” button is clicked on the dashboard, the “C:\Temp\Script1.ps1” file is executed and displayed within the code editor located on the dashboard.