Multiple Powershell Commands in batch file

Hi,

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 <glenns@xxxx.com>" -SmtpServer "outlook.xxxx.com"  -from "U
er02 <johni@nbad.com>" -subject "Test mail" -attachments "c:\report\ir000003.pdf"

PS C:\users\farooquia> send-mailmessage -to "User01 <jack@xxx.com>" -SmtpServer "outlook.xxxx.com"  -from "U
er02 <john@xxxx.com>" -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

Thanks
ahmedla1Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Raheman M. AbdulConnect With a Mentor Senior Infrastructure Support Analyst & Systems DeveloperCommented:
try:

send-mailmessage -to "User01 <glenns@xxxx.com>" -SmtpServer "outlook.xxxx.com"  -from "Uer02 <johni@nbad.com>" -subject "Test mail" -attachments @("c:\report\ir000003.pdf","c:\report\ir000006.pdf")
0
 
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
just store all the commands in a filename.ps1 file  (note extension: ps1) and run in powershell
eg:

PS  c:\> c:\filename.ps1
0
 
ahmedla1Author Commented:
IHi,

Thanks for your reply. I don't want to run it within power shell.
0
 
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
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
0
 
ahmedla1Author Commented:
Excellent. Thanks for your assistance.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.