Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Multiple Powershell Commands in batch file

Posted on 2014-01-31
Medium Priority
Last Modified: 2014-01-31

I require execute a number (10) of powershell commands. Is it possible to store them in a batch file? How do I execute the powershell commands within the batch file?

PS C:\users\farooquia> send-mailmessage -to "User01 <>" -SmtpServer ""  -from "U
er02 <>" -subject "Test mail" -attachments "c:\report\ir000003.pdf"

PS C:\users\farooquia> send-mailmessage -to "User01 <>" -SmtpServer ""  -from "U
er02 <>" -subject "Test mail" -attachments "c:\report\ir000003.pdf"

Also, please advise how can I attach more than one file to the above command eg report ir000003.pdf and ir000006.pdf

Question by:ahmedla1
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 39823765
just store all the commands in a filename.ps1 file  (note extension: ps1) and run in powershell

PS  c:\> c:\filename.ps1

Author Comment

ID: 39823774

Thanks for your reply. I don't want to run it within power shell.
LVL 19

Expert Comment

by:Raheman M. Abdul
ID: 39823779
save the following line in filename.bat:

%windir%\system32\windowspowershell\v1.0\powershell.exe -command psfile.ps1

and save all your powershell commands in psfile.ps1 file
LVL 19

Accepted Solution

Raheman M. Abdul earned 2000 total points
ID: 39823784

send-mailmessage -to "User01 <>" -SmtpServer ""  -from "Uer02 <>" -subject "Test mail" -attachments @("c:\report\ir000003.pdf","c:\report\ir000006.pdf")

Author Closing Comment

ID: 39824031
Excellent. Thanks for your assistance.

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : All lightning effects with instructions : http://www.mediaf…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question