Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Registry File Remotely with PowerShell

I'm using the following script to run test.reg on multiple remote systems:

$computers = Get-Content computers.txt

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

The script doesn't error, but the registry entry doesn't import on any of the systems.

I know test.reg file is a valid registry file because I copied it over, ran it manually, and the registry key imports. I also made sure PowerShell Remoting is enabled on the remote computers.

Any ideas why the registry key isn't importing?

like image 482
blashmet Avatar asked Apr 22 '15 16:04

blashmet


1 Answers

I found the best way not to mess with issues related to server authentication and cut down on complexity just to pass Reg file as parameter to function.

$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
like image 60
Gregory Suvalian Avatar answered Oct 06 '22 03:10

Gregory Suvalian