I'm struggling to find the answer to this. I need to take two values, one is an input type "Printer Name" and the other is a dropdown value "DCdropdown", and I need to take those values given and assign them to certain parts of powershell script and then run the script. I know the script that I need to write, but I don't know how to take the values and add it to the script and then run it when I hit the "Make it so" button. This is what I have so far:
<p>Which printer would you like to add?</p>
<input type="text" placeholder="Printer Name" id="myInput">
<script>
function getInputValue(){
// Selecting the input element and get its value
var inputVal = document.getElementById("myInput").value;
// Displaying the value
alert(inputVal);
}
</script>
<p>Which Distribution Center are you located?</p>
<select id="DCdropdown" onchange="leaveChange(this)">
<option value=""></option>
<option value="xxx">CMB</option>
<option value="xxx">DS</option>
<option value="xxx">FNO</option>
<option value="xxx">GNWD</option>
<option value="xxx">JAX</option>
<option value="xxx">RMVL</option>
</select>
<button type="button" onclick="getInputValue();">Make it so</button>
<script>
function myFunction(){
document.getElementByID
}
</script>
This is impossible without additional infrastructure, and this is by design.
Web browsers cannot run PowerShell code. You would at a minimum need to be running a web application which can execute PowerShell code on its end. This could be listening on the local machine, or it could be remote. But it's not happening with only the browser alone, and it's not happening with raw JavaScript.
If this is part of a webapp being served then this is possible but still would have to be done by executing something on the webserver itself, can't be done from the browser on the local machine. In any event suggesting a solution in this space exceeds the scope of this question.
In theory a custom browser plugin (not extensions) could facilitate this this but AFAIK all major browsers either no longer support plugins or disable them by default, and you have to ensure such a plugin is installed.
Edit: I forgot about a newer technology called Blazor that lets dotnet run under WebAssembly (and in theory PowerShell), but it would not be useful here as it is sandboxed to the browser just as Javascript and other site code is.