r/PowerShell • u/Affectionate-Fix-766 • Apr 30 '26
How to trigger a local PowerShell script from a web browser?
Hi everyone,
We’ve developed a Microsoft Teams application for enterprise use. Currently, the installation process requires admins to manually run a PowerShell script. They essentially have to copy the script, open PowerShell, and run it themselves.
To be honest, this feels a bit "amateur" and isn't the best user experience. We want to streamline this. Ideally, I’d like the user to click a button on our web dashboard that automatically triggers the PowerShell script on their local machine to complete the setup.
We haven't found a way to bridge the browser-to-PowerShell gap yet. Is there a professional way to achieve this? Or are there better alternatives for automating Teams app deployment that we’re overlooking?
Thanks in advance!
61
u/MNmetalhead Apr 30 '26
This makes me instantly think of malware deployments. Yikes.
25
u/Fatel28 Apr 30 '26
You can't do this and you don't want to do this. If a browser could run arbitrary code on your machine, it would be a CVE not a feature
6
u/derekhans Apr 30 '26
Post the script.
A compiled MSI and push to your workstations is really the professional way to handle this. There is also creating a Teams app manifest and deploying it via the Teams portal. Without knowing what the script is and does, it's hard to know which way to go.
3
u/SHANE523 Apr 30 '26
Deploy through Group Policy?
2
u/SysAdminDennyBob Apr 30 '26
Dude, install some infrastructure to manage your clients. This is a long-solved problem. There are a wide swath of workstation management products on the market and all of them will run a powershell script on your clients for you.
23
u/arslearsle Apr 30 '26
Devs - thinking about deployment after product is finished
Why is this a never ending shitshow?
What deploy system you have in place? On prem dc? Intune? NinjaOne? Ps remoting enabled on client pcs?
13
u/N0bleC Apr 30 '26
A solution could be powershell universal dashboard, which is not free however.
12
u/lavahot Apr 30 '26
That's the neat part: you don't.
10
u/SVD_NL Apr 30 '26
Is deploying the app via admin portal not possible? Manage custom apps in Microsoft Teams admin center | MS Learn
Otherwise Intune or RMM is the solution. If an admin doesn't have a solution for running PS scripts on their endpoints, they did this to themselves.
If you really can't make that work, the best option would be to bundle the ps1 file with a .cmd or bat that runs the script file (can be useful if you need to give executionpolicy parameters for example).
5
u/somethingblerg Apr 30 '26
I think this might belong on r/ShittySysadmin not PowerShell.
But seriously, if you have a legitimate need to deploy something use your management tools (Intune, CM, RMM, GPO, Invoke-Command (https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/invoke-command?view=powershell-7.6)
Having users conditioned to click a button to run random scripts is how you lose your lunch.
4
u/cjcox4 Apr 30 '26
Browser -> "service" -> powershell.
It's that "service" piece that you need to provide/implement/deploy that creates a path (hopefully secure) to execute the powershell.
1
u/da_chicken Apr 30 '26
What are you using for application deployment that doesn't permit you to make the kinds of changes that the script performs? Why can't you just package the script with a deployment?
1
u/BlackV Apr 30 '26 edited Apr 30 '26
No shade, but I agree It does seem 100% amature , 365/teams has an app ecosystem already, why can you not use that?
Launching a script directly from a webpage is always, always suspicious
Aside from you using a PowerShell script to "install" it, what makes this PowerShell related?
2
u/strongest_nerd Apr 30 '26
Why can't the rmm be used to run the script?
2
u/420GB Apr 30 '26
Is this for internal employees only? Simply push the script via Intune or your software deployment solution.
For external / any user in the world, no, you can't simply run a PowerShell script on their computer by having them visit a website. That would be a huge security issue. You can give them a one-line install command though (irm into iex)
2
u/justaguyonthebus Apr 30 '26
Provide a msi installer option so enterprise can deploy it like literally everything else. You can do other things in addition, but that's the primary professional option.
2
u/mylsotol Apr 30 '26
Don't
2
u/falken227 Apr 30 '26
As others have already said, this is a bad idea to allow for malware/cybersecurity reasons.
Probably your best bet would be to create a simple shortcut to allow your admins to run the script. Set the target to be the Powershell executable with the script as the file parameter
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file "\\server\directory\script.ps1""C:\Program Files\PowerShell\7\pwsh.exe" -file "\\server\directory\script.ps1"You can go into the advanced options and check the box to make it run as Admin if required.
2
u/thehuntzman May 01 '26
This is somehow a worse idea than those sites that deploy software by telling you to paste some form of powershell.exe -command "iex(<url>)" in the run box...
1
u/ArieHein Apr 30 '26
Pode
1
u/Tymanthius Apr 30 '26
How do you deploy other software?
1
u/jay791 Apr 30 '26
On user button press, make a call to your backend and provide computer name or IP. Your backend then opens a remote powershell session to this computer/ip and executes whatever in that remote session.
Make sure your backend runs with rights that allow doing stuff on that computer (or can use impersonation to do so).
1
u/GreatMyUsernamesFree Apr 30 '26
Why not just have them add their name to an install queue with one button on a regular web form? Let Power Automate read the queue, target the user's PC and run the powers shell script? This will accomplish what you've asked for but I personally would have just went the last mile and added an installer so you can fully hand it off to your hardware team. Your application sounds like it's really close to being finished.
1
u/LogMonkey0 Apr 30 '26
Might want to consider looking at Azure automation or azure function
1
u/OldManMot Apr 30 '26
Could you make it a login script?
1
u/Skinny_que Apr 30 '26
I want to say no because there’s no way for you to know their local set up.
Like if it’s on a gov computer etc that’s blocked immediately.
Also launching code like this would get flagged by any reasonable intrusion detection / antivirus system
1
u/OneStandardCandle Apr 30 '26
You would need to package and deploy this as an app. The best way to permit on-demand user installs may be to make it available via Company Portal.
1
u/Meannekes Apr 30 '26
Intune is your friend to deploy stuff on machines
1
u/alconaft43 Apr 30 '26
the only right way is intune company portal. Use psdtk.
1
u/Sin_of_the_Dark Apr 30 '26
Group policy? SCCM? Intune? All would be infinitely better and nobody in their right mind would allow a browser to execute arbitrary code on their local machine.
1
u/Future-Remote-4630 May 01 '26
There was a powershell summit presentation about WEBJea, which is in that same vein.
https://github.com/markdomansky/webjea