rapid7/metasploit-framework — pull request #3390 by TomSellers (2014-05-25 13:11:20+00:00)
Title: Improve reliability of have_powershell

I have a case where on a Windows 2008 R2 host with PowerShell 2.0 the **have_powershell** method times out. When I interactively run the command I find that the output stops after the PowerShell command and the token from **cmd_exec** is NOT displayed. When I hit return the shell then processes the '&echo ' and generates the token that **cmd_exec** was looking for.

I tried various versions of the PowerShell command string such as 'Get-Host;Exit(0)', '$PSVErsionTable.PSVersion', and '-Command Get-Host' but was unable to change the behavior. I found that adding 'echo. | ' simulated pressing enter and did not disrupt the results on this host or on another host where the **have_powershell** method functioned as expected. As a note, both shells were created using **exploit/windows/smb/psexec**.

There may be a better solution, but this was the only one that I could find.