I have typescipt Client side application. I have powershell scipt which gives the value of Azure key vault secret in that VM. Now i need to include this scipt in typescipt code to get the value of Script result. How can we get this?
-
You can't, the browser acts as a sandbox. If you want the user to execute a PowerShell you're gonna have to ask them to do it – Mathias R. Jessen Apr 27 '21 at 10:43
-
Is it useful to you ? https://stackoverflow.com/questions/10179114/execute-powershell-script-from-node-js && https://learn.microsoft.com/en-us/javascript/api/overview/azure/keyvault-admin-readme?view=azure-node-preview – Jason Pan Apr 28 '21 at 01:54
1 Answers
It would be a security vulnerability if your browser could directly execute code outside the browser sandbox. Instead, you can use the Azure Key Vault SDK for JavaScript (written in and optimized for TypeSCript) to retrieve secrets directly.
You'll need to authenticate the user, though. Typically this is done on the backend, for which your web service might authenticate the user and either impersonate them (depending on authentication workflow), or make the request directly as the web site as long as the user has access. This is probably more often the case.
There's really no reason to use PowerShell in this case if you just want your web page to get a secret. If this question is really about how to authenticate a user in that case, please elaborate and consider adjusting tags to better clarify why you are trying to have them use PowerShell instead (which still requires they authenticate and are authorized).

- 2,986
- 18
- 21