Call PowerShell script PS1 from another PS1 script inside Powershell ISE

后端 未结 11 1087
伪装坚强ぢ
伪装坚强ぢ 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 16:07

    This is just additional info to answers in order to pass argument into the another file

    Where you expect argument

    PrintName.ps1

    Param(
        [Parameter( Mandatory = $true)]
        $printName = "Joe"    
    )
    
    
    Write-Host $printName
    

    How to call the file

    Param(
        [Parameter( Mandatory = $false)]
        $name = "Joe"    
    )
    
    
    & ((Split-Path $MyInvocation.InvocationName) + "\PrintName.ps1") -printName $name
    

    If you do not do not provide any input it will default to "Joe" and this will be passed as argument into printName argument in PrintName.ps1 file which will in turn print out the "Joe" string

提交回复
热议问题