0

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
Stratos
  • 5
  • 2

1 Answers1

2

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
Community
  • 1
  • 1
vonPryz
  • 22,996
  • 7
  • 54
  • 65