How to check if a Powershell script is running remotely

后端 未结 5 1881
渐次进展
渐次进展 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条回答
  •  -上瘾入骨i
    2020-12-19 09:08

    Get-Host returns, amongst other information a Name:

    PS> (Get-Host).Name
    ConsoleHost
    PS> (Invoke-Command -ComputerName dev2 -Script {Get-Host}).Name
    ServerRemoteHost
    

提交回复
热议问题