#requires -version 2 # Disable and stop the remote registry service on a list of computers. # Author: Joakim Svendsen. Svendsen Tech. # BSD 3-clause license. $ComputerName = @('server2012', 'vista64esxi', 'server2008') foreach ($Computer in $ComputerName) { if ($Status = Get-Service -ComputerName $Computer -Name RemoteRegistry -EA SilentlyContinue | Select -ExpandProperty Status) { if ($Status -eq 'Running') { # Send a stop signal and then try to set it to disabled. # Using sc.exe really should be the easiest and/or most versatile way here. sc.exe "\\$Computer" stop remoteregistry | Out-Null Write-Output "${Computer}: Fired off a stop signal for the RemoteRegistry service." Start-Sleep -Milliseconds 500 sc.exe "\\$Computer" config remoteregistry start= disabled | Out-Null if ($?) { Write-Output "${Computer}: Successfully set RemoteRegistry service to disabled." } else { Write-Warning "${Computer}: Failed to set RemoteRegistry service to disabled. Aborting processing of this computer." continue } Start-Sleep -Milliseconds 250 if ($Status = Get-Service -ComputerName $Computer -Name RemoteRegistry -EA SilentlyContinue | Select -ExpandProperty Status) { Write-Output "${Computer}: Current status of RemoteRegistry service is: $Status. It might need some more time." } else { Write-Warning "${Computer}: Unable to determine if service is running after starting it and sleeping a little." } } else { Write-Output "${Computer}: The RemoteRegistry service is not running." } } else { Write-Warning "${Computer}: Unable to determine if service is running. Aborting processing of this computer." } }