Powershell - 在 CMD 上运行命令 - 通配符抛出错误 [英] Powershell - Running Command on CMD - Wildcards Throw Error

查看:33
本文介绍了Powershell - 在 CMD 上运行命令 - 通配符抛出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 CMD 运行以下 Powershell 命令:

I am trying to run the following Powershell command via CMD:

powershell -command "Get-WmiObject Win32_Process | Where-Object {$_.CommandLine -like \"*C:\Windows\Test*\" } | Select-Object ProcessName, CommandLine"

上面的命令直接在 Powershell 上运行良好,但只有在我尝试在 CMD 上运行时才会出现问题.在我的测试中,我发现 * 符号无法正确处理,我试图在测试符号前放一个反斜杠,但没有成功.有没有办法让它与 CMD 中的 * 符号一起使用?

The command above runs fine directly on Powershell, but only causes problems when I try to run it on CMD. In my testing, I discovered that the * symbol fails to process correctly, I tried to put a backslash before the symbol for testing and that has not done the trick. Is there a way to get this to work with the * symbol in CMD?

此命令用于查看包含 C:\Windows\Test

This command is used to view processes that contain a command-line of C:\Windows\Test

推荐答案

更简单,不需要 PowerShell:

wmic process where "commandline like '%c:\\windows\\test%'" get name, commandline

为了完整起见,为了保持正确的主题,使用 cmd.exe 中的 PowerShell,我会更像这样:

And just for completeness, to remain properly on topic, using PowerShell from cmd.exe, I'd do it more like this:

powershell -noprofile "get-ciminstance -query \"select * from win32_process where commandline like '%c:\\windows\\test%'\" | select-object -property processname, commandline"

这篇关于Powershell - 在 CMD 上运行命令 - 通配符抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆