Stratos
Stratos

Reputation: 5

Redirect Powershell output available to command line

I was wondering how to make available powershell variable in order to be read from the command line. Is that possible?

The command is

get-wmiobject win32_networkadapter -filter "netconnectionstatus = 2" | Select -Expand macaddress -Last 1 | set-variable -name mac1

Upvotes: 0

Views: 342

Answers (1)

vonPryz
vonPryz

Reputation: 24071

There isn't Powershell in DOS, so I'd guess you have a CMD script (i.e. a .bat or .cmd file) that needs to assign a variable returned from Powershell. This is suprisingly quite tricky.

C:\>for /f "delims=" %i in ('powershell -command " & {  get-wmiobject win32_networkadapter -filter 'netconnectionstatus
= 2' | Select -Expand macaddress -Last 1 } "') do set foobar=%i

C:\>set foobar=00:19:99:E1:98:32

C:\>echo %foobar%
00:19:99:E1:98:32

Upvotes: 2

Related Questions