简体   繁体   English

如何使用PowerShell脚本运行命令行参数

[英]How to run command line argument using PowerShell script

I am able to install the software from the Windows CMD with the following command 我可以使用以下命令从Windows CMD安装该软件

setup.exe -inputFile C:\my_installer_input.txt

However, I want to achieve the same above using the PowerShell script. 但是,我想使用PowerShell脚本实现与上述相同的功能。

I tried same from the PowerShell like this 我从PowerShell这样尝试过

Start-Process -FilePath "C:\Matlab R2018b\setup.exe" -inputFile "C:\my_installer_input.txt" -ArgumentList "/S

and it fails to run with the obvious reason -inputFile parameter is not available for Start-Process in PowerShell. 并且由于以下原因而无法运行: -inputFile参数不可用于PowerShell中的Start-Process

PowerShell also runs the native commands directly from PowerShell prompt, which means your command PowerShell还直接从PowerShell提示符运行本机命令,这意味着您的命令

setup.exe -inputFile C:\my_installer_input.txt

should work directly from the PowerShell prompt. 应该直接在PowerShell提示符下工作。

If you are executing on a remote machine, you can run with Invoke-Command as below. 如果在远程计算机上执行,则可以使用Invoke-Command运行,如下所示。

Invoke-Command -Session $session -ScriptBlock { <YOUR CODE HERE> }

or 要么

Invoke-Command -ComputerName <remote-computername> -ScriptBlock { <YOUR CODE HERE> }

If this is on a remote machine, do something like: 如果在远程计算机上,请执行以下操作:

   Invoke-Command -Computername ‘x’ -Scriptblock {
Set-Location C:\path\to\file
    cmd /c setup.exe /arg1 /arg2
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM