Call PowerShell script PS1 from another PS1 script inside Powershell ISE

后端 未结 11 1089
伪装坚强ぢ
伪装坚强ぢ 2020-12-12 15:27

I want call execution for a myScript1.ps1 script inside a second myScript2.ps1 script inside Powershell ISE.

The following code inside MyScript2.ps1, works fine from

11条回答
  •  清歌不尽
    2020-12-12 15:56

    The current path of MyScript1.ps1 is not the same as myScript2.ps1. You can get the folder path of MyScript2.ps1 and concatenate it to MyScript1.ps1 and then execute it. Both scripts must be in the same location.

    ## MyScript2.ps1 ##
    $ScriptPath = Split-Path $MyInvocation.InvocationName
    & "$ScriptPath\MyScript1.ps1"
    

提交回复
热议问题