大网数据广告活动
服务器运维问答

WMIC Command works, but doesn't work in powershell script

· 52CE 我爱测

#Get Data Rate wmic "/OUTPUT:'C:\Users\user\Documents\DATE RATE\Data_Rate-ts8"+".txt" nic where 'NetEnabled = True' 'get Name,MacAddress,Speed'" Running this in the console directly works. That is only because in the console, I c…

问题原文

原帖链接 · Faahmed · CC BY-SA 3.0

#Get Data Rate
wmic "/OUTPUT:'C:\Users\user\Documents\DATE RATE\Data_Rate-ts8"+".txt" nic where 'NetEnabled = True' 'get Name,MacAddress,Speed'"

Running this in the console directly works. That is only because in the console, I can do this:

ps C:\>wmic
wmic:root\cli>/OUTPUT:"C:\Users\user\Documents\DATE RATE\Data_Rate-ts8"+".txt" nic netenabled ="True"
wmic:root\cli>exit
ps C:\>

In the powershell script, I can't simply type WMIC first and then the rest of the command or else it interrupts the script by entering the WMIC prompt, waiting for user to type and is no longer executing the script.

When I put it in a powershell script (first snippet), I keep getting:

No Alias Found

I've tried different combinations of quotes. But the script I posted above specifically gives me:

"/OUTPUT:'C:\Users\user\Documents\DATE RATE TESTS\Data_Rate-ts8'+'.txt' nic where 'NetEnabled = True' 'get Name - Alias not found.

已采纳解答

原帖链接 · Clayton · CC BY-SA 3.0

Are you determined to continue using WMIC? If you're using powershell you may find it more useful to use the native powershell cmdLets to obtain the same information.

Depending on what you're doing with the file, this may allow you to skip the file. You could also pipe the WMI query results to | foreach { }

get-wmiobject Win32_NetworkAdapter -filter 'NetEnabled = True' | select-object Name,MacAddress,Speed | format-list | out-file dataRate.txt

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-01-08)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。