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

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.