A PowerShell script can be executed from any “Command Line Interface (CLI)” tool such as “Command Prompt” or “Terminal”. Moreover, the PowerShell script can be executed from another script using PowerShell ISE.
This tutorial will overview a complete procedure to resolve the mentioned procedure.
How to Call/Invoke PowerShell Script from Another Script Inside PowerShell ISE?
The PowerShell script can be invoked/called from another script using these methods:
Method 1: Use the “Call Operator” Method to Call/Invoke PowerShell Script from Another Script
First method to call the PowerShell script from another script is the “Call Operator” method. Call operator “&” or invocation operator is used in PowerShell to call commands stored in the variable and the files and scripts stored on the system.
Example
Let’s call the PowerShell script from another script using the “Call operator &”. For instance, overview the mentioned command:
In the above code:
- First of all, add the call operator “&” followed by the script file path.
- After that, specify the script path that needs to be executed:
It can be observed from the output that the script has been successfully called from another script using the call operator “&”.
Method 2: Use the “Dot Sourcing” Method to Call/Invoke PowerShell Script from Another Script
The “Dot Sourcing” feature helps you to call the PowerShell script from another script as follows:
According to the given command:
- First of all, we have added the “Dot Source” which is a dot, followed by the script file path.
- Finally, execute this code as a PowerShell script to call the PowerShell script:
As you can observe, the PowerShell script has been called from another script.
Conclusion
The PowerShell script “.ps1” can be called from another “.ps1” script using various methods, including the “Call Operator” and the “Dot Sourcing” method. Both of these methods use the path of the PowerShell script to call it in its script. This post has elaborated multiple methods to call the PowerShell “.ps1” script from another “.ps1” script.