A few weeks ago, a colleague asked if I knew of a way to script the change or modification of the Registered Owner / Organization information on a Windows Server system (2003 or 2008). I knew that this could be achieved with PowerShell and had some initial ideas, so I spent a few minutes whipping up the script below.
For this to work, you should ideally have all systems on the same Windows Domain and have enabled PowerShell remoting on each system that needs to be changed. Of course you could also just run the script on a single workstation/server on its own without the need for PSRemoting.
# On all remote machines that need their info changed Set-ExecutionPolicy RemoteSigned Enable-PSRemoting # Say yes to all prompts
#region This part only needed if machines do not belong to the same domain... # Note: This can be a security risk, only use if you are sure you want to allow any host as a trusted host. (e.g. fine for lab environments) cd wsman::localhost\client Set-Item .\TrustedHosts * # Say yes to all prompts #endregion
# Run on your management machine/machine you are using to update all others... $computers = @("SERVER1","SERVER2","SERVER3") foreach ($computer in $computers) { Enter-PSSession $computer cd 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion' Set-ItemProperty -Path . -Name "RegisteredOwner" -Value "Auth User" Set-ItemProperty -Path . -Name "RegisteredOrganization" -Value "Lab" Exit-PSSession }
So the above should update your registered owner and organization details for each server listed in the $computers array. (Specify your own host names here). The above script should be easy enough to modify if you are looking to change other registry entries. Finally, don’t forget that you should always be careful when updating registry, especially via script – make sure you have backups!
Hi Jon,
Thanks for the feedback. I never got around to testing the remoting. Good to learn more about the use cases of Enter/Exit-PSSession! I’ll definitely be remembering Invoke-Command for remoting in future. Thanks for the example too 🙂
Cheers,
Sean
Nice post 🙂
Enter / Exit-PSSession is mainly aimed at interactive use. If you want to run this kind of thing against multiple servers you’ll find it better to run Invoke-Command. By default this will run against 32 servers concurrently, e.g.
Invoke-Command -ComputerName “Server1″,”Server2″,”Server3” -ScriptBlock {$path = ‘HKLM:\Software\Microsoft\Windows NT\CurrentVersion’;Set-ItemProperty -Path $path -Name “RegisteredOwner” -Value “Auth User”;Set-ItemProperty -Path $path -Name “RegisteredOrganization” -Value “Lab”}
Happy remoting!