Ok, I finally wrestled this one to the ground, but it is a little complicated and unintuitive. First off, if the you have a Powershell script and it doesn’t need administrative mode, you have to run it this way. Hat tip to Raymond for this one.
powershell.exe -File ".\install.ps1"
As should be obvious in retrospect, in WSL, you use forward slash but when calling real Windows programs you use the backslash
Then if you need something to run with Administrative privileges, this is a real pain in Windows. In the graphical interfaces, you have to right click on a command in the Start menu and choose Run as Administrator
, but if you want to do it from a script you utter:
runas.exe /savecred /user:some_user_name "powershell.exe -File .\install.ps1"
I’ll leave it for a reader to remember how to quote things, but basically, runas.exe, unlike Bash, expects the whole thing in a single string.
The real run is what user account to use, the current easy default is that Windows uses your Microsoft Account for login, but you cannot use that for this command. There is a trope that says that if you switch your Windows account to a local account and then create a local password and then switch it back again, then you can use that local account password. This didn’t work at all for me.
Also note the /savecred
this stores that password somewhere inside Windows so you don’t have to type it again.