Solved

Multiple Powershell Commands in batch file

Posted on 2014-01-31
5
1,366 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 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
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 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
0
 
LVL 18

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
This article will help you understand what HashTables are and how to use them in PowerShell.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

862 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

23 Experts available now in Live!

Get 1:1 Help Now