My Tech Scrap
Flipkart.com

Translate

Share |

Wednesday, 15 February 2023

Powershell script to add and update registry Dword in list of remote servers

$servers = Get-Content 'C:\Lab\servers.txt' # Path to list of servers $keyPath = 'SOFTWARE\Example'#Software means HKEY_LOCAL_MACHINE\SOFTWARE\ $valueName = 'ExampleValue' #DWORD Name $valueData = 12 # Dword Value foreach ($server in $servers) { $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $server) $key = $reg.OpenSubKey($keyPath, $true) if ($key -eq $null) { Write-Host "Registry key not found, adding." + $keyPath $key = $reg.CreateSubKey($keyPath, $true) } $key = $reg.CreateSubKey($keyPath, $true) $key.SetValue($valueName, $valueData, [Microsoft.Win32.RegistryValueKind]::DWord) }

No comments:

Post a Comment