0
如何獲取當前正在執行的命令或腳本的當前路徑?無法將參數綁定到參數'Path',因爲它爲空
嘗試下面的腳本:
$scriptpath = $MyInvocation.MyCommand.Path
write-host $scriptpath
,並調用它像這樣:
invoke-command -computername localhost -filepath .\test.ps1
也試過以下,但得到了一個空白行:
invoke-command -scriptblock { write-host $MyInvocation.MyCommand.Path }
回答:http://stackoverflow.com/a/5220517/520612 –
可能重複[在腳本調用Invoke命令時在PowerShell中獲取腳本目錄](http://stackoverflow.com/questions/5219461/獲得腳本目錄功能於PowerShell的時候,腳本被調用的與 - 調用命令) –