locked
Create install.bat File to run Powershell script RRS feed

  • Question

  • Hi ,

      I have a powershell scripts (.ps1 file) I have to run the powershell script file from install.bat.

    could you please let me know any one if any samples or links

    Regards

    Patil

     

    Thursday, July 28, 2011 5:23 AM

Answers

  • Hi Patil,

    Its very easy. Follow this step by step guide:

    Assuming you have kept a powershell script called helloworld.ps1 in folder "c:\ps"  (this is just example, you can have different path)

    Contents of helloworld.ps1 are:

    Write-Host "Hello World"
    

    Now in the same folder (i.e. "c:\ps") create a batch file called Helloworld.bat. Contents of bat file should be:

    powershell .\helloworld.ps1


    save both files and close them.

    Now just double click on the bat file and it will run the powershell script from same directory.

    you can customize this scenario to suit your purpose. Just remember to put in bat file the way I have done.


    A random burst of technology notes Blog: http://rhythmiccoding.blogspot.com
    • Marked as answer by Wayne Fan Thursday, August 4, 2011 5:39 AM
    Friday, July 29, 2011 6:04 AM
  • You can directly put PowerShell code into a batch/cmd file without having to also have a separate .ps1 file. Patil, You might check: http://dmitrysotnikov.wordpress.com/2008/06/27/powershell-script-in-a-bat-file/

    Also if the purpose of batch file is just triggering of PowerShell script than you can create a shortcut with a target like this: powershell -file D:\scripts\myscripts\connect.ps1 Configure the shortcut to run as administrator. Then double-click the shortcut.


    Leonid Lyublinski Wizard of MOSS

    • Marked as answer by Wayne Fan Thursday, August 4, 2011 5:39 AM
    Monday, August 1, 2011 6:22 PM

All replies

  • Hi Patil,

    Its very easy. Follow this step by step guide:

    Assuming you have kept a powershell script called helloworld.ps1 in folder "c:\ps"  (this is just example, you can have different path)

    Contents of helloworld.ps1 are:

    Write-Host "Hello World"
    

    Now in the same folder (i.e. "c:\ps") create a batch file called Helloworld.bat. Contents of bat file should be:

    powershell .\helloworld.ps1


    save both files and close them.

    Now just double click on the bat file and it will run the powershell script from same directory.

    you can customize this scenario to suit your purpose. Just remember to put in bat file the way I have done.


    A random burst of technology notes Blog: http://rhythmiccoding.blogspot.com
    • Marked as answer by Wayne Fan Thursday, August 4, 2011 5:39 AM
    Friday, July 29, 2011 6:04 AM
  • hi there,

    were you able to create the batch file to run power shell scripts?


    A random burst of technology notes Blog: http://rhythmiccoding.blogspot.com
    Monday, August 1, 2011 5:05 PM
  • You can directly put PowerShell code into a batch/cmd file without having to also have a separate .ps1 file. Patil, You might check: http://dmitrysotnikov.wordpress.com/2008/06/27/powershell-script-in-a-bat-file/

    Also if the purpose of batch file is just triggering of PowerShell script than you can create a shortcut with a target like this: powershell -file D:\scripts\myscripts\connect.ps1 Configure the shortcut to run as administrator. Then double-click the shortcut.


    Leonid Lyublinski Wizard of MOSS

    • Marked as answer by Wayne Fan Thursday, August 4, 2011 5:39 AM
    Monday, August 1, 2011 6:22 PM
  • Want to write batch file which contains multiple powershell scipt files, needs to run automatically when double clicked on it, no need to go at powershell command.

    How to write it?

    Monday, December 5, 2011 10:29 AM