Powershell

Call PowerShell Script PS1 from Another PS1 Script Inside PowerShell ISE

PowerShell is a scripting language utilized to perform administrative and automation tasks. It offers a dedicated host application, “PowerShell ISE”, used to create and execute scripts. The extension of PowerShell scripts is “.ps1”.

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:

> & "C:\Doc\Script.ps1"

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:

> . C:\Doc\Script.ps1

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.

About the author

Muhammad Farhan

I am a Computer Science graduate and now a technical writer who loves to provide the easiest solutions to the most difficult problems related to Windows, Linux, and Web designing. My love for Computer Science emerges every day because of its ease in our everyday life.