powershell - 用于将 .reg 文件导入远程计算机挂起的 PowerShell 脚本
问题描述
我正在使用以下脚本将 .reg 文件导入远程计算机。我需要发生的事情如下:
- 连接到远程计算机并杀死正在运行的进程(如果它正在运行)。
- 将 .reg 密钥文件从网络共享位置复制到远程计算机。
- 将复制的 .reg 密钥导入远程计算机的注册表。
- 从远程计算机中删除复制的 .reg 密钥文件。
- 启动一开始就被杀死的进程。
现在我对 PowerShell 脚本编写相对较新,并且我拥有的脚本部分是从我在互联网和我的 PowerShell Cookbook 中找到的脚本蚕食的。
当我运行脚本时会发生什么,它将连接到远程计算机并终止进程,但随后脚本被挂起,并且不执行步骤 2-5。它也没有抛出任何错误。我错过了什么或做错了什么?
提前致谢!
#Variables
$Computers = Get-Content C:\computer.txt
$LocalRegFileName = "regfile.reg"
$HostedRegFile = "\\NETWORK-SHARE\Folder\Folder\regfile.reg"
$ProcessName = "Process"
$FilePath = "C:\Program Files (x86)\Folder\$ProcessName.exe"
foreach ($Computer in $Computers) {
Invoke-Command -ComputerName $Computer {
Get-Process -Name $ProcessName | Stop-Process -Force
}
$NewFile = "\\$Computer\C'$\TEMP\$LocalRegFileName"
New-Item -ErrorAction SilentlyContinue -ItemType directory -Path \\$Computer\C$\TEMP
Copy-Item $HostedRegFile -Destination $NewFile
Invoke-Command -ComputerName $Computer -ScriptBlock {
Start-Process -FilePath "C:\Windows\regedit.exe" -ArgumentList "/s C:\TEMP\$LocalRegFileName"
}
Invoke-Command -ComputerName $Computer -ScriptBlock {
Remove-Item "C:\TEMP\$LocalRegFileName"
}
Invoke-Command -ComputerName $Computer -ScriptBlock {
Start-Process -FilePath "$FilePath\$ProcessName.exe"
}
}
解决方案
推荐阅读
- function - 如何在 c 文件中使用长命令运行系统功能?
- python-3.x - 如何使用已知顶点坐标的三角形生成 Mayavi triangular_mesh 的“三角形”参数
- angular - Angular firebase 有很多变量
- c# - 为什么用户输入的最小数字没有被添加到列表中?
- javascript - 如何将文本复制到剪贴板?
- rust - 如何使用 Tokio 从子进程的 stdout 和 stderr 异步读取?
- single-page-application - Apple Watch 中的 PWA 和 SPA 支持
- aws-lambda - 无服务离线类型错误:无法读取 null 的属性“accessKeyId”
- twitter-bootstrap - 推特应用审核需要多长时间?
- java - Java 中的布局问题 - 在 JFrame 底部设置一个 20% 不透明的面板