简体   繁体   中英

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

There isn't Powershell in DOS, so I'd guess you have a CMD script (ie 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM