我使用以下脚本在多个远程系统上运行test.reg
:
$computers = Get-Content computers.txt
Invoke-Command -ComputerName $computers -ScriptBlock {
regedit /i /s "\\SERVER\C$\RegistryFiles\test.reg"
}
脚本没有错误,但注册表项不会导入任何系统。
我知道test.reg
文件是一个有效的注册表文件,因为我将其复制,手动运行,并导入注册表项。我还确保在远程计算机上启用了PowerShell远程处理。
注册表项无法导入的任何想法
答案 0 :(得分:5)
我找到了最好的方法,不要弄乱与服务器身份验证相关的问题,并减少复杂性只是为了将Reg文件作为参数传递给函数。
$regFile = @"
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters]
"MaxUserPort"=dword:00005000
"TcpTimedWaitDelay"=dword:0000001e
"@
Invoke-Command -ComputerName computerName -ScriptBlock {param($regFile) $regFile | out-file $env:temp\a.reg;
reg.exe import $env:temp\a.reg } -ArgumentList $regFile
答案 1 :(得分:1)
我发布了一些PowerShell论坛,最终实现了这一点。
我不得不1)在循环中移动$ newfile变量,2)注释$ newfile变量中存储的路径中的$。
作为参考,如果有人想要使用它,最终脚本如下所示:
$servers = Get-Content servers.txt
$HostedRegFile = "C:\Scripts\RegistryFiles\test.reg"
foreach ($server in $servers)
{
$newfile = "\\$server\c`$\Downloads\RegistryFiles\test.reg"
New-Item -ErrorAction SilentlyContinue -ItemType directory -Path \\$server\C$\Downloads\RegistryFiles
Copy-Item $HostedRegFile -Destination $newfile
Invoke-Command -ComputerName $server -ScriptBlock {
Start-Process -filepath "C:\windows\regedit.exe" -argumentlist "/s C:\Downloads\RegistryFiles\test.reg"
}
}