Calling Windows scripts from Linux
If you're used to running PowerShell in Windows, then you will also be used to being able to directly call PowerShell cmdlets and scripts. When you are running PowerShell scripts in WSL, you have two options: install PowerShell for Linux or call PowerShell in Windows to run the script. If you are interested in PowerShell for Linux, the install documentation can be found at https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7. However, since this chapter is focused on calling Windows from WSL, we will look at the latter option.
PowerShell is a Windows application and is in the Windows path, so we can call it using powershell.exe
from Linux, as we saw in the last section. To run a command with PowerShell, we can use the -C
switch (short for -Command
):
$ powershell.exe -C "Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System" Component Information...