Summary: Learn to find the name of the Windows PowerShell host.
How can I determine if I am running a Windows PowerShell script in the Windows PowerShell console?
Use the Get-Host cmdlet. Here is how to check:
if((Get-Host).name -ne "consolehost") {"Take appropriate action here"}