在 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 &.