Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
232 views
in Technique[技术] by (71.8m points)

Running CMD command in PowerShell

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.

Here is the command:

"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)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try this:

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...