【问题标题】:Redirect Powershell output available to command line重定向可用于命令行的 Powershell 输出
【发布时间】:2015-01-20 12:33:48
【问题描述】:
我想知道如何使 powershell 变量可用以便从命令行读取。这可能吗?
命令是
get-wmiobject win32_networkadapter -filter "netconnectionstatus = 2" | Select -Expand macaddress -Last 1 | set-variable -name mac1
【问题讨论】:
标签:
windows
powershell
command-line
【解决方案1】:
DOS 中没有 Powershell,所以我猜您有一个需要分配从 Powershell 返回的变量的 CMD 脚本(即 .bat 或 .cmd 文件)。这是suprisingly相当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