Solved

Multiple Powershell Commands in batch file

Posted on 2014-01-31
5
1,454 Views
Last Modified: 2014-01-31
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
Comment
Question by:ahmedla1
  • 3
  • 2
5 Comments
 
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
eg:

PS  c:\> c:\filename.ps1
0
 

Author Comment

by:ahmedla1
ID: 39823774
IHi,

Thanks for your reply. I don't want to run it within power shell.
0
 
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
0
 
LVL 19

Accepted Solution

by:
Raheman M. Abdul earned 500 total points
ID: 39823784
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
 

Author Closing Comment

by:ahmedla1
ID: 39824031
Excellent. Thanks for your assistance.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

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.
A procedure for exporting installed hotfix details of remote computers using powershell
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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