How to run the .reg file using PowerShell?
How about using reg.exe instead of regedit.exe
Get-Command reg
CommandType Name Version Source
----------- ---- ------- ------
Application reg.exe 10.0.16... C:\Windows\system32\reg.exe
this worked for me fine:
reg import .\test.reg
You may be trying to run it with insufficient privileges. This snippet should work:
$startprocessParams = @{
FilePath = "$Env:SystemRoot\REGEDIT.exe"
ArgumentList = '/s', 'C:\file.reg'
Verb = 'RunAs'
PassThru = $true
Wait = $true
}
$proc = Start-Process @startprocessParams
if ($proc.ExitCode -eq 0) {
'Success!'
}
else {
"Fail! Exit code: $($Proc.ExitCode)"
}
Pause
I use
Invoke-Command {reg import \\server\share\test.reg *>&1 | Out-Null}
the last part
*>&1 | Out-Null
pipes the output to null so the console doesn't see it. I do not think this is required but it annoyed me.