2015-04-22 97 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" 

    } 

    } 
相關問題