Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to restart a service on a remote machine using PowerShell. The service has both a displayname and an instancename. Can I use the Restart-Service cmdlet to do this? I don't see an instancename parameter, and I can't seem to make the "displayname$instancename" syntax work.

This syntax does not work:

Invoke-Command -Session $session -ScriptBlock {Restart-Service -displayname 'DisplayName$InstanceName' -PassThru}

I thought at first the problem was the $ character, but I found that this syntax does work:

Get-Service 'displayname$instancename'
share|improve this question

Try switching to single quotes in the first command. The double quotes are preforming variable substitution.

share|improve this answer
I just tried with it with single quotes... no luck. I'll update my question to remove the double quotes. – dthrasher Aug 17 '12 at 18:52
He is saying use double quotes instead of single quotes. If you use double quotes, it will substitute the value of a variable. If you use single quotes, it treats it just as a string of characters, without substituting values. – Nick Aug 17 '12 at 20:48

I use the following code to restart services on remote systems. You might need to add the -credentials tag if you don't have permissions. This is really nice because it works on Server 2003/Windows XP boxes as well.

$Service = "InstanceNameOfService"
$Computer = "MyComputer"
$varService = Get-WmiObject -computername $Computer -class win32_service | Where-Object { $_.Name -eq $Service }
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.