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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
Synchronize a new Active Directory domain with an existing Office 365 tenant
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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

10 Experts available now in Live!

Get 1:1 Help Now