0

I've been trying to integrate a PowerShell script inside a Batch file but I seem to get some errors when trying to do so.

This is my code so far:

for /F "tokens=* delims=," %%A in (C:\MACs.log) do (

@ECHO OFF
PowerShell.exe "& arp -a | select-string "%%A" |% {$_.ToString().Trim().Split(" ")[0]} >> C:\tempfile.log

Ok so, when I run this command in PowerShell everything is working OK but in Batch I get some token errors.

The main post of this code is to create a loop from the MACs.log where I have a couple of MAC addresses that I want the IP addresses to and output them to tempfile.log.

If someone can lend a helping hand it would be greatly appreciated.

1
  • Why? Just run the PowerShell script directly. Commented Mar 3, 2015 at 15:34

1 Answer 1

1

Why not directly solve it from the batch file?

(for /f %%a in ('
    arp -a ^| findstr /l /i /g:"c:\MACs.log" 
') do @echo %%a) > c:\tempfile.log

The inner pipe command will execute the arp and filter its output using the mac addresses found in MACs.log. This list is processed by the for /f command that will retrieve the first token in the line (default behaviour), that is, the ip address, and echo it. All the output is sent to a tempfile.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the feedback. The Powershell string seemed easier initially. I'm gonna use the code you suggested. Thx a lot! Cannot upvote your post as I don't have enough Rep... +1 :D

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.