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 think it's possible in your script test if
$myinvocation.mycommand.path -eq $null
then if is true is running remotely via Invoke-command.
true
I have not test it accurately but I think it can work.