I use the following function:
function Start-RemoteRegistryService {
<#
.SYNOPSIS
Starts the Remote Registry service on a remote computer.
.DESCRIPTION
Starts the Remote Registry service on a remote computer. The WinRM service must be running and not blocked by firewall rules, and the person using this cmdlet must have sufficient rights to start and stop services on the remote computer.
.PARAMETER ComputerName
The name of the computer to start the Remote Registry service on.
.INPUTS
ComputerName accepts any object with a member property named ComputerName
.OUTPUTS
[System.Integer]
A zero return indicates successful start of the Remote Registry service on the target computer.
.EXAMPLE
PS C:\> Start-RemoteRegistryService -ComputerName LAB01
Starts the Remote Registry service on computer LAB01
#>
[CmdletBinding()]
Param (
[Parameter(ValueFromPipelineByPropertyName=$true)]
[String]$ComputerName
)
try {
$RemoteRegistry = Get-CIMInstance -Class Win32_Service -Comp $ComputerName -Filter "Name='RemoteRegistry'"
if ($RemoteRegistry.State -ne "Running") {
return Invoke-CIMMethod -InputObject $RemoteRegistry -MethodName StartService
}
}
catch {
throw
}
}
(I’d originally planned on better error handling, but I’ve had too much hands on my time...)
The original version used WMI but was almost identical:
function Start-RemoteRegistryService {
<#
.SYNOPSIS
Starts the Remote Registry service on a remote computer.
.DESCRIPTION
Starts the Remote Registry service on a remote computer. The WinRM service must be running and not blocked by firewall rules, and the person using this cmdlet must have sufficient rights to start and stop services on the remote computer.
.PARAMETER ComputerName
The name of the computer to start the Remote Registry service on.
.INPUTS
ComputerName accepts any object with a member property named ComputerName
.OUTPUTS
[System.Integer]
A zero return indicates successful start of the Remote Registry service on the target computer.
.EXAMPLE
PS C:\> Start-RemoteRegistryService -ComputerName LAB01
Starts the Remote Registry service on computer LAB01
#>
[CmdletBinding()]
Param (
[Parameter(ValueFromPipelineByPropertyName=$true)]
[String]$ComputerName
)
try {
$rrstatus = (Get-Service -ComputerName $ComputerName -Name RemoteRegistry).Status
if ($rrstatus -ne "Running") {
if ($ComputerName -eq $env:ComputerName) {
Start-Service -Name RemoteRegistry
} else {
return ((Get-WmiObject -ComputerName $ComputerName -Class Win32_Service -Filter "Name='RemoteRegistry'").StartService()).ReturnValue
}
}
}
catch {
throw
}
}