Difference between revisions of "Registry Windows"
Jump to navigation
Jump to search
| Line 7: | Line 7: | ||
Migrate | Migrate | ||
| + | ``` | ||
| + | $DST_HOST = "example.com" | ||
| + | $Session = New-PSSession -ComputerName $DST_HOST | ||
| + | foreach ( $TP in (Get-ChildItem -Path Cert:LocalMachine\MY).Thumbprint ) { | ||
| + | reg export "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SystemCertificates\MY\Certificates\$TP" $env:TEMP\cert.$TP.reg | ||
| + | $Session = New-PSSession -ComputerName $DST_HOST | ||
| + | $DST_TMP_DIR = (invoke-command $DST_HOST -ScriptBlock { write-output $env:TEMP }) | ||
| + | Copy-Item -Path "$env:TEMP\cert.$TP.reg" -ToSession $Session -Destination "$DST_TMP_DIR\" *>&1 | out-null | ||
| + | invoke-command $DST_HOST -ScriptBlock { reg.exe import "$env:TEMP\cert.$Using:TP.reg" } *>&1 | out-null | ||
| + | } | ||
| + | ``` | ||
| + | |||
| + | Migrate Specific Cert based on CN - Use -Like with * for regex | ||
``` | ``` | ||
$DST_HOST = "foo.example.com" | $DST_HOST = "foo.example.com" | ||
Revision as of 22:22, 2 November 2023
Export & Import via Registry even Non-Exportable
Get existing
Get-ChildItem -Path Cert:LocalMachine\MY | select subject
Migrate
$DST_HOST = "example.com"
$Session = New-PSSession -ComputerName $DST_HOST
foreach ( $TP in (Get-ChildItem -Path Cert:LocalMachine\MY).Thumbprint ) {
reg export "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SystemCertificates\MY\Certificates\$TP" $env:TEMP\cert.$TP.reg
$Session = New-PSSession -ComputerName $DST_HOST
$DST_TMP_DIR = (invoke-command $DST_HOST -ScriptBlock { write-output $env:TEMP })
Copy-Item -Path "$env:TEMP\cert.$TP.reg" -ToSession $Session -Destination "$DST_TMP_DIR\" *>&1 | out-null
invoke-command $DST_HOST -ScriptBlock { reg.exe import "$env:TEMP\cert.$Using:TP.reg" } *>&1 | out-null
}
Migrate Specific Cert based on CN - Use -Like with * for regex
$DST_HOST = "foo.example.com"
$CN="CN=foo, OU=bar"
$TP=(Get-ChildItem -Path Cert:LocalMachine\MY | where Subject -eq "$CN").Thumbprint
reg export "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SystemCertificates\MY\Certificates\$TP" $env:TEMP\cert.$TP.reg
$Session = New-PSSession -ComputerName $DST_HOST
Copy-Item -Path $env:TEMP\cert.$TP.reg -ToSession $Session -Destination "$env:TEMP\"
invoke-command $DST_HOST -ScriptBlock { reg.exe import "$env:TEMP\cert.$Using:TP.reg" }
Other
$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