If you want to call a PowerShell script (Test2.ps1) with named parameters from a PowerShell script (Test1.ps1), you can’t use the & operator, like & “C:\Temp\Test2.ps1” –Computer L001 –User User1, because the & command is an alias for the Get-Command cmdlet. The Get-Command cmdlet executes precisely one command, see : http://powershell.com/cs/blogs/ebook/archive/2009/03/30/chapter-12-command-discovery-and-scriptblocks.aspx#the-call-operator-quotampquot, but you can use script blocks to execute more then one command or the Invoke-Expression cmdlet. I used the Invoke-Expression cmdlet to call a PowerShell script with named parameters from an other PowerShell script.


$command = “C:\Temp\Test2.ps1” –Computer L014 –User User1

Invoke-Expression $command




    [string]$Computer = "MyDefaultComputer",
    [string]$User = "MyDefaultUser"










  1. Thanks for the example, short and to the point. Just started PS and not sure if a PowerGui bug but:
    $command =“C:\Temp\Test2.ps1” –Computer L014 –User User1

    Had to move the quote to the end to get this to work

    $command =“C:\Temp\Test2.ps1 –Computer L014 –User User1″

  2. If the path contains spaces, enclose it in single quotes and prefix it with &
    $command =”&’C:\Temp\Test 2.ps1′ –Computer L014 –User ‘User 1′”

    Marc Derksen

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.