Executing another Powershell script

Published on: 16th Dec 2019

Updated on: 3rd Aug 2025

Explanation

To run a Powershell script file in the current directory.

.\test1.ps1
Write-Output "done"

To run a Powershell script file name that is stored in the same script location while the script file name is kept in a variable. In that you can you need to use & symbol to invoke the script.

$ps_file = "$PSScriptRoot\test1.ps1"
& $ps_file
Write-Output "done"

Notes

& symbol lets you to execute a command, script file or script block.

Use case

Back to #POWERSHELL blog

Back to #blog listing