When running a wsl.exe command in Powershell, it can be needed/useful to pipe the output inside the WSL shell instead of Powershell (see Run commands across WSL distros In order to achieve that, we need to use the wsl.exe -- instead of wsl.exe --exec command as we need the WSL shell to be spawned (which --exec doesn’t do). Finally, we also need to “escape” the pipe character so it’s not interpreted by Powershell:

wsl.exe -- cat /etc/hosts `| grep localhost