Is it possible to detect from a powershell profile whether powershell has been invoked interactively or not? I see some people using $host.name but it seems to always return ConsoleHost.

  • i THINK you can do it with this >>> [System.Environment]::UserInteractive <<< – Lee_Dailey Jan 27 at 8:02
  • 1
    You may want to check out this question...stackoverflow.com/questions/9738535/… – Dallas Jan 27 at 14:39
  • @Lee_Daily, that seems to always return True for me, either from a script pwsh -noni test.ps1 or in a command block: pwsh -noni -c '[System.Environment]::UserInteractive. – xdhmoore Jan 27 at 18:02
  • @Dallas thanks that's probably as good as I'm going to get. Too bad there's not a better way than checking the flags on the process... – xdhmoore Jan 27 at 18:04
  • It looks like [System.Environment]::UserInteractive is not referring to an interactive shell exactly... and here – xdhmoore Jan 27 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.