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 Powershell Administration, but doesn’t work inside PowerShell ISE:
#Call myScript1 from myScript2
invoke-expression -Command .\myScript1.ps1
I obtain the following error when I execute MyScript2.ps1 from PowerShell ISE:
The term ‘.\myScript1.ps1’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
In order run a script in the same directory.
In PowerShell 3.0 and later you can use the automatic variable
$PSScriptRoot:In PowerShell 1.0 and 2.0 you should use this specific property:
The reason you should use that and not anything else can be illustrated with this example script.
Here are some results.
In PowerShell 3.0 and later you can use the automatic variable
$PSScriptRoot: