How to check if a Powershell script is running remotely

后端 未结 5 1821
渐次进展
渐次进展 2020-12-19 09:04

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

5条回答
  •  醉梦人生
    2020-12-19 09:17

    Checking whether $profile is defined works for me. I don't know how reliable this is, but various sources suggest that no profile is loaded in the remote session. I couldn't check the computername, as I don't have any way of knowing in advance which machine is local and which is remote.

    $RunningLocally = $profile -ne $null
    

提交回复
热议问题