Windows Sandbox PowerShell logon command window not visible

3.1k Views Asked by At

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.

1

There are 1 best solutions below

7
Tomáš Hübelbauer On BEST ANSWER

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 file
  • start powershell runs another PowerShell with visible window
    • Running this directly for LogonCommand will not work
    • -noexit tells the nested PowerShell to remain visible
      • This is not necessary but it is useful for debugging the script errors
    • -file C:\Users\WDAGUtilityAccount\Desktop\boot.ps1 runs the given script
      • Share it with the machine by using a MappedFolder in the WSB configuration