Multiple Powershell Commands in batch file

Posted on 2014-01-31
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
  • 3
  • 2
LVL 18

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 18

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 18

Accepted Solution

Raheman M. Abdul earned 500 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now