Get script directory in PowerShell when script is invoked with Invoke-Command

后端 未结 2 1577
醉话见心
醉话见心 2021-01-13 08:00

I have a set of PowerShell scripts that include a \"common\" script, located in the same folder, like this:

# some-script.ps1
$scriptDir = Split-Path -Parent         


        
2条回答
  •  我在风中等你
    2021-01-13 08:36

    alternatively rather than using filepath.. you could pass in a scriptblock, that dotsources the script from a UNC path that all machines have access to. However each machine will need to have the appropriate executionpolicy set so that they can run that script from the UNC path

    let me be clear though, that i'm not saying to run the script from the UNC path as if that does the remoting, but still using invoke-command or start-job to run a scriptblock on a remote computer. It just happens that that scriptblock will run the script from a UNC path for convenience.

提交回复
热议问题