none
Launch multiple .ps1 scripts with one .bat file

    Question

  • ·          

    I have created a “launch.bat” file to open PS in my script directory and it works perfectly fine.

    Start powershell  -noexit -command cd  D:\Scripts\Myscripts

    I also have some .ps1 scripts in my script folder, and I run the below scripts at least five times a day on different machines, and follow the same sequence daily.

    A)    Browse to my script folder "D:\Scripts\Myscripts

    B)    run   "..load ps1"

    C)    .format.ps1

    D)    .install.ps1

    Is it possible to run the above scripts one after the other with one single “launch.bat “ file.

     

    Thanks in advance

    Thursday, July 14, 2011 5:11 AM

Answers

  • $ScriptPath = Split-Path $MyInvocation.MyCommand.Path
    . "$ScriptPath\load.ps1"
    . "$ScriptPath\format.ps1"
    . "$ScriptPath\install.ps1"
    


    Put the above script in a file called D:\Scripts\MyScripts\Wrapper.ps1, then call this:

    powershell.exe -command ". 'D:\Scripts\MyScripts\Wrapper.ps1'"



    If this post was helpful, please click the little "Vote as Helpful" button :)

    Trevor Sullivan
    http://trevorsullivan.net

    Friday, July 15, 2011 3:25 PM
    Moderator

All replies

  • Just put all of them in another script file and lauch that script.

     

     


    jv
    • Marked as answer by Kochumon Nair Friday, July 15, 2011 4:43 AM
    • Unmarked as answer by Kochumon Nair Friday, July 15, 2011 4:43 AM
    Thursday, July 14, 2011 6:33 AM
  • I had tried that but it dint work, maybe i have not done it the correct way.

    It would really help if you give me an example and maybe i will be able to create one by reffering the example.

     

     

    Friday, July 15, 2011 4:52 AM
  • Create a file with a PS1 extransion and any name you like.

    Put these lines in the file.

    Set-Location D:\Scripts\Myscripts
    
    .\load ps1
    
    .\format.ps1
    
    .\install.ps1
    
    
    
    
    
    
    
    

    To run

    .\<your new file name>/ps1

    replace the <> and everything in the midde with the name of the new file.

     


    jv
    Friday, July 15, 2011 9:29 AM
  • $ScriptPath = Split-Path $MyInvocation.MyCommand.Path
    . "$ScriptPath\load.ps1"
    . "$ScriptPath\format.ps1"
    . "$ScriptPath\install.ps1"
    


    Put the above script in a file called D:\Scripts\MyScripts\Wrapper.ps1, then call this:

    powershell.exe -command ". 'D:\Scripts\MyScripts\Wrapper.ps1'"



    If this post was helpful, please click the little "Vote as Helpful" button :)

    Trevor Sullivan
    http://trevorsullivan.net

    Friday, July 15, 2011 3:25 PM
    Moderator
  • Ok I clicked - now what?

    Good example Trevor.

     


    jv
    Friday, July 15, 2011 4:58 PM
  •  

    It worked, i added couple of more scripts and they all run in sequence with no issues.

    Thanks for your help :)

    I have One more question.

    I have a new .ps1 script what has to be run with some additional parameter

    I added this script and tried to run, how it fails with error “not recognized as the name of a cmdlet”


    $ScriptPath = Split-Path $MyInvocation.MyCommand.Path
    . "$ScriptPath\load.ps1"
    . "$ScriptPath\format.ps1"
    . "$ScriptPath\install.ps1"
    . "$ScriptPath\Primary-Connection.ps1 -Site MBX –Import"

     

    If I run this manually it works .\Primary-Connection.ps1 -Site MBX –Import

    What do I need to do to run it when I call  .\wrapper.ps1

     

     

    Thanks

    Koch Nair

     

    Thursday, July 21, 2011 6:02 AM