Time and time again you may have the need to access something in a remote computer’s registry. This recently was the case for me so I decided to script it up and put it in a function. If you need to Remotely Enable RemoteRegistry Service than take a few minutes to copy this script and save it to the location of your choice. This script uses the CimInstance to see if the service is auto started, running or disabled and needs to be enabled.
I should note that since this script is using CIM cmdlets you need to enable PSRemoting on client Operating Systems such as Windows 10 and Windows 8.1. This will not work on a Windows 7 machine with Powershell 2.0 since CIM cmdlets were introduced with Version 3.0. If you want to use it on client computers and older operating systems, switch Get-CimInstance with Get-WmiObject…
Remotely Enable RemoteRegistry with Powershell
#requires -RunAsAdministrator #requires -Version 3.0 Function Enable-RemoteRegistry { <# .Synopsis This will enable the remote registry service on local or remote computers. For updated help and examples refer to -Online version. .DESCRIPTION This will enable the remote registry service on local or remote computers. For updated help and examples refer to -Online version. .NOTES Name: Enable-RemoteRegistry Author: The Sysadmin Channel Version: 1.0 DateCreated: 2018-Jun-21 DateUpdated: 2018-Jun-21 .LINK https://thesysadminchannel.com/remotely-enable-remoteregistry-service-powershell - .EXAMPLE For updated help and examples refer to -Online version. #> [CmdletBinding()] param( [Parameter( ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] [string[]] $ComputerName = $env:COMPUTERNAME ) BEGIN {} PROCESS { Foreach ($Computer in $ComputerName) { try { $RemoteRegistry = Get-CimInstance -Class Win32_Service -ComputerName $Computer -Filter 'Name = "RemoteRegistry"' -ErrorAction Stop if ($RemoteRegistry.State -eq 'Running') { Write-Output "$Computer is already Enabled" } if ($RemoteRegistry.StartMode -eq 'Disabled') { Set-Service -Name RemoteRegistry -ComputerName $Computer -StartupType Manual -ErrorAction Stop Write-Output "$Computer : Remote Registry has been Enabled" } if ($RemoteRegistry.State -eq 'Stopped') { Start-Service -InputObject (Get-Service -Name RemoteRegistry -ComputerName $Computer) -ErrorAction Stop Write-Output "$Computer : Remote Registry has been Started" } } catch { $ErrorMessage = $Computer + " Error: " + $_.Exception.Message } } } END {} }
Once you dot source the function and run the command with a specified computer name it will respond with either, the service is already running, the service has been enabled and/or the service has been started.
If you liked this post be sure to check out TheSysadminChannel on Youtube. And if you’re looking to further your Powershell or SCCM knowledge, be sure to check out Learn Powershell In a Month Of Lunches Book for Powershell and Learn SCCM in a Month of Lunches Book for System Center Configuration Manager.