How to check if a Powershell script is running remotely

Question:

I have a script that can be run either locally or remotely (via WinRM), however I would like it to behave slightly differently when run on a remote machine. I realise that I can pass in a switch to the script to identify whether it is running locally or remotely, but I want to know if it is possible for the script itself to detect whether it is running remotely?

Answer:

Get-Host returns, amongst other information a Name:

Source:

How to check if a Powershell script is running remotely by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply