在 PowerShell 中运行 CMD 命令 [英] Running CMD command in PowerShell

查看:80
本文介绍了在 PowerShell 中运行 CMD 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行 PowerShell 命令时遇到了很多问题.它所做的只是运行一个将在 CMD 提示窗口中运行的命令.

I am having a bunch of issues with getting a PowerShell command to run. All it is doing is running a command that would be run in a CMD prompt window.

这是命令:

C:Program Files (x86)Microsoft Configuration ManagerAdminConsoleini386CmRcViewer.exe"PCNAME

我尝试了以下但没有成功(我已经尝试了很多次迭代来尝试获得一个有效的.语法可能都搞砸了):

I have tried the following with no success (I have tried many iterations of this to try and get one that works. Syntax is probably all screwed up):

$TEXT = $textbox.Text #$textbox is where the user enters the PC name.
$CMDCOMMAND = "C:Program Files (x86)Microsoft Configuration ManagerAdminConsoleini386CmRcViewer.exe"
Start-Process '"$CMDCOMMAND" $TEXT'
#iex -Command ('"C:Program Files (x86)Microsoft Configuration ManagerAdminConsoleini386CmRcViewer.exe"' $TEXT)

该命令只会打开用户在文本框中指定的计算机的 SCCM 远程连接窗口.

The command will just open SCCM remote connection window to the computer the user specifies in the text box.

推荐答案

试试这个:

& "C:Program Files (x86)Microsoft Configuration ManagerAdminConsoleini386CmRcViewer.exe" PCNAME

对 PowerShell 而言,字符串..."只是一个字符串,PowerShell 通过将其回显到屏幕来对其进行评估.要让 PowerShell 执行名称在字符串中的命令,请使用调用运算符 &.

To PowerShell a string "..." is just a string and PowerShell evaluates it by echoing it to the screen. To get PowerShell to execute the command whose name is in a string, you use the call operator &.

这篇关于在 PowerShell 中运行 CMD 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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