I'm trying to use Windows Sandbox with a PowerShell logon command. This is the LogonCommand
section of my WSB file:
<LogonCommand>
<Command>C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -executionpolicy unrestricted -file "C:\\Users\\WDAGUtilityAccount\\Desktop\\boot.ps1" -noexit</Command>
</LogonCommand>
The Windows Sandbox instance loads up okay suggesting no syntactic/validation issues with the WSB file content, but the PowerShell window is not shown. Adding -windowstyle normal
has no effect.
I suspect the LogonCommand
content is run in a command prompt which is not made visible so running the command to open PowerShell from it somehow "inherits" the terminal window not being visible.
Is it possible to force the PowerShell terminal window to reveal itself in such a case? I want to do this so that I can see the errors that I get because the PowerShell script is not executing as expected and I'm blind to any output/progress indication.
Found an answer (doesn't look like the cleanest option, but works):
<Command>powershell -executionpolicy unrestricted -command "start powershell {-noexit -file C:\Users\WDAGUtilityAccount\Desktop\boot.ps1}"</Command>
powershell
switches from CMD to PowerShell
-windowstyle normal
won't work to make this PowerShell window visible-executionpolicy unrestricted
allows the nested PowerShell to run from filestart powershell
runs another PowerShell with visible window
LogonCommand
will not work-noexit
tells the nested PowerShell to remain visible
-file C:\Users\WDAGUtilityAccount\Desktop\boot.ps1
runs the given script
MappedFolder
in the WSB configuration