Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1937
  • Last Modified:

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
0
ahmedla1
Asked:
ahmedla1
  • 3
  • 2
1 Solution
 
Raheman M. AbdulCommented:
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. AbdulCommented:
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
 
Raheman M. AbdulCommented:
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
 
ahmedla1Author Commented:
Excellent. Thanks for your assistance.
0

Featured Post

 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now