You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为远程复制安装证书的PowerShell循环脚本添加回车暂停提示

解决方案

你只需要在ForEach循环体的末尾,单台服务器的证书安装逻辑之后,添加Read-Host命令即可实现等待用户按回车继续的效果,修改后的完整脚本如下:

$servers = Get-Content "D:\scripts\InstallCertRemote\servers.txt"
$LocalPath = "D:\Temp\*.*"
$RemotePath = "D$\Temp\certificates"
$logfile = "D:\scripts\InstallCertRemote\logfile.txt"

ForEach ($server in $servers)
{
    Get-Date | out-file $logfile -Append
    Write-host Copying files on $server
    copy-item -Path $LocalPath -Destination "\\$server\$RemotePath" -Verbose 4>&1 | out-file $logfile -Append
    Start-Sleep 2
    Write-host Installing certificate on $server
    Invoke-Command -ComputerName "$server" -ScriptBlock {Import-Certificate -FilePath "S:\temp\certificates\certificate.cer" -CertStoreLocation Cert:\LocalMachine\ROOT} -Verbose 4>&1 | out-file $logfile -Append
    # 新增暂停逻辑,等待用户按回车
    Read-Host -Prompt "按回车键继续..."
}
  • 新增的Read-Host -Prompt "按回车键继续..."会在每台服务器的证书安装完成后触发,脚本会暂停运行,直到你按下回车键才会开始处理下一台服务器。
  • 如果后续需要取消暂停自动批量执行,直接注释或删除该行即可。

内容的提问来源于stack exchange,提问作者RAN55

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 07:45:01