首页 > 解决方案 > 在PowerShell中正确使用cmd

问题描述

目前我用批处理将程序安装到远程机器上。那已经很好了。但是我如何在powershell中使用或“转换”下面的批处理命令,使用prgramm的特定命令在远程机器上静默安装?这是我的批处理代码。

set /p target=hostname 
echo.
copy /z "\\server1\tool.exe" "\\%target%\C$\temp"
echo.
PsExec.exe \\%target% cmd /c "\\%target%\C$\temp\tool.exe" /verysilent

标签: powershell

解决方案


$target=hostname
Copy-Item -Path "\\server1\tool.exe" -Destination "\\$target\C$\temp"
Invoke-Command -ScriptBlock \\%target%\C$\temp\tool.exe -ComputerName $target -credential (USERNAME)

forInvoke-Command -Scriptblock是您要运行的命令,-ComputerName是您要在其上启动进程的计算机,-Credential是用于运行命令的用户名。系统将自动提示您输入密码。


推荐阅读