2015-04-22 85 views
3

我使用下面的脚本来在多个远程系统上运行test.reg远程文件:运行注册表使用PowerShell

$computers = Get-Content computers.txt 

Invoke-Command -ComputerName $computers -ScriptBlock { 
    regedit /i /s "\\SERVER\C$\RegistryFiles\test.reg" 
} 

的脚本没有错误,但该注册表项不上任何的进口系统。

我知道test.reg文件是一个有效的注册表文件,因为我复制它,手动运行它,并注册表项导入。我还确保远程计算机上启用了PowerShell远程处理。

任何想法为什么注册表项不导入?

+1

可能是双跳问题。你能读取脚本块内的reg文件吗(例如用'Get-Content')? –

+1

什么配置单元是你的注册表文件test.reg使用? – Colyn1337

+0

@ Colyn1337 - HKEY_LOCAL_MACHINE \ SOFTWARE \ Test – blashmet

回答

3

我找到了最好的办法不乱用有关服务器认证的问题并减少复杂性只是为了打发注册文件作为参数来运行。

$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 
+0

不错!这比复制.reg文件好。 – blashmet

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" 

    } 

    } 
相关问题