We help IT Professionals succeed at work.

what powershell command to run batch file job

motioneye
motioneye asked
on
1,892 Views
Last Modified: 2012-05-08
Hi,
I have batch file, how do I use powershell to execute the batch file, something like calling this file btw.bat ?
Comment
Watch Question

CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Bill PrewTest your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016

Commented:
You should just be able to type the name of the BAT file if it is in a directory in your PATH.  If it is in the current directory then preface it with ".\" as below.

.\foo.bat

~bp
CERTIFIED EXPERT

Commented:
command line:

powershell.exe -noexit .\btw.bat

Author

Commented:
actually I want to run it within the powershell scripts, so can it be as simple as typing .\foo.bat in the scripts or ?
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Hi,
Ok here is my scripts, the output is not the results which I'm looking for. The bat file contain only ping command.

$servers = get-content "F:\PowerShell_Myscripts\AllServers.txt"
@(ForEach ($server in $servers){
   .\btw.bat
}) | Export-CSV "F:\PowerShell_Myscripts\result.csv" -notype
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
LearnctxEngineer
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
I must use bacth file... that the problem.. so how do I proceed
LearnctxEngineer
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.