powershell - 在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
解决方案
$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
是用于运行命令的用户名。系统将自动提示您输入密码。
推荐阅读
- javascript - 设置 vuetify 扩展面板组件的 max-width
- ruby - 带有“while”或“until”循环的数组算法
- android - 限制用户可以使用 Firebase 邀请的邀请数量
- visual-c++ - 检查文件中的非终止块语句
- javascript - 如何通过自定义本地 .html 打开多个 url-web-links?
- r - 使用最接近的匹配值交叉引用两个表
- php - Laravel 从表单传递数组并在控制器中解析
- ios - 如何在 WebView iOS-swift 中使用 InputStream 预览文件
- python - Python 解析 json 数据到 Netezza 表
- python - 时间序列数据框。绘制具有相对起点的两个不同时间范围