I was looking for a way to add registry keys to multiple remote servers. Discovering the fact that legacy commands like REG ADD works in Powershell was pure bliss. The following simple script will add/verify registry entries remotely.

$ServerList = Get-Content RegList.txt
foreach( $Server in $ServerList)
{
Write-host -foregroundcolor Cyan Server Name : $Server
$x=””
# Add the registry keys
REG ADD \\$Server\HKLM\Software\GigaTrust\GTBESExtension /v InstallPath /t REG_EXPAND_SZ /d “D:\PROGRAM FILES\GIGATRUST”
REG ADD \\$Server\HKLM\Software\GigaTrust\GTBESExtension /v PurgeCheckIntervalMinutes /t REG_DWORD /d 15
REG ADD \\$Server\HKLM\Software\GigaTrust\GTBESExtension /v PurgeCutoffDays /t REG_DWORD /d 30
REG ADD \\$Server\HKLM\Software\GigaTrust\GTBESExtension /v RMCachePath /t REG_EXPAND_SZ /d “D:\PROGRAM FILES\GIGATRUST\BESRMCACHE”
# Verify the keys
REG QUERY \\$Server\HKLM\Software\GigaTrust\GTBESExtension /v InstallPath
REG QUERY \\$Server\HKLM\Software\GigaTrust\GTBESExtension /v PurgeCheckIntervalMinutes
REG QUERY \\$Server\HKLM\Software\GigaTrust\GTBESExtension /v PurgeCutoffDays
REG QUERY \\$Server\HKLM\Software\GigaTrust\GTBESExtension /v RMCachePath
write-host -foregroundcolor Yellow “Press any key to to continue”
# Command to wait for user to press a key.
$x = $host.UI.RawUI.ReadKey(“NoEcho,IncludeKeyDown,AllowCtrlC”)
}
Write-host -foregroundcolor Green “Completed”

The result will look like this:

– Thanks, Jinesh.

Advertisements