• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1924
  • Last Modified:

Powershell 2.0 problems

Hi Experts.  I'm just starting to cut my teeth on Powershell so bear with me please.  While following along on a tutorial, I was supposed to run this command to stop/start a service after checking the services status.  

PS C:\MyScripts> stop-service -name fax

I verified that the service is not set to disabled by checking via services.msc and see that it is actually set to Manual:[blank].  I was able to run [start-service -name fax] which started the service but when I run the command above [stop-service -name fax], I get this error:

Stop-Service : Cannot find any service with service name '-Fax'.
At line:1 char:13
+ Stop-Service <<<<  -Name -Fax
    + CategoryInfo          : ObjectNotFound: (-Fax:String) [Stop-Service], Se
   rviceCommandException
    + FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.
   Commands.StopServiceCommand

If I manually stop the service, I am unable to start it again.  I get this error:


Start-Service : Service 'Fax (Fax)' start failed.
At line:1 char:14
+ Start-Service <<<<  -Name Fax
    + CategoryInfo          : OpenError: (System.ServiceProcess.ServiceControl
   ler:ServiceController) [Start-Service], ServiceCommandException
    + FullyQualifiedErrorId : StartServiceFailed,Microsoft.PowerShell.Commands
   .StartServiceCommand

So, why can I start it with the PS command but not stop it or after stopping it manually via the services.msc, why can't I start it again?  Again, I'm sure I am overlooking something but I really would like to learn this and appreciate your help.

--I am a local admin on this box if that matters
0
samiam41
Asked:
samiam41
1 Solution
 
Seaton007Commented:
Maybe try with the display name: http://technet.microsoft.com/en-us/library/ee177005.aspx

Does it have dependent services?  You may need to use the -force switch: http://www.activexperts.com/network-monitor/windowsmanagement/powershell10/0138
0
 
samiam41Author Commented:
Thanks seaton007 for the quick reply and information.  The display name and service name are the same in this instance.  Fax/fax

I will check the -force switch now.
0
 
samiam41Author Commented:
The -force syntax just seemed to piss it off more.  I get a variety of error messages as I am trying it different ways (never used it in PS before) and following the site you sent me is to stop the service.  I can't force start it either (tried).
0
SMB Security Just Got a Layer Stronger

WatchGuard acquires Percipient Networks to extend protection to the DNS layer, further increasing the value of Total Security Suite.  Learn more about what this means for you and how you can improve your security with WatchGuard today!

 
dicconbCommented:
Hi samiam,

From the error it looks like you've mistyped it as
Stop-Service -Name -Fax

Open in new window

Can you double-check that you're definitely typing
Stop-Service -Name Fax

Open in new window

as this should work.

Welcome to the world of Powershell!

D
0
 
samiam41Author Commented:
Thanks dicconb!  I used this command [start-service fax] and got this error:

Start-Service : Service 'fax (Fax)' start failed.
At line:1 char:14
+ start-service <<<<  fax
    + CategoryInfo          : OpenError: (System.ServiceProcess.ServiceControl
   ler:ServiceController) [Start-Service], ServiceCommandException
    + FullyQualifiedErrorId : StartServiceFailed,Microsoft.PowerShell.Commands
   .StartServiceCommand

PS C:\MyScripts> start-service -name fax
Start-Service : Service 'fax (Fax)' start failed.
At line:1 char:14
+ start-service <<<<  -name fax
    + CategoryInfo          : OpenError: (System.ServiceProcess.ServiceControl
   ler:ServiceController) [Start-Service], ServiceCommandException
    + FullyQualifiedErrorId : StartServiceFailed,Microsoft.PowerShell.Commands
   .StartServiceCommand

Can you use that command on your pc?
0
 
samiam41Author Commented:
I tried another service [disk defragmenter] which I could start and stop a couple of times using the services.msc.  When I tried the command, no dice.

PS C:\MyScripts> start-service -name "disk defragmenter"
Start-Service : Service 'disk defragmenter (defragsvc)' cannot be started due t
o the following error: Cannot open defragsvc service on computer '.'.
At line:1 char:14
+ start-service <<<<  -name "disk defragmenter"
    + CategoryInfo          : OpenError: (System.ServiceProcess.ServiceControl
   ler:ServiceController) [Start-Service], ServiceCommandException
    + FullyQualifiedErrorId : CouldNotStartService,Microsoft.PowerShell.Comman
   ds.StartServiceCommand

So it isn't just the fax service.  I can't seem to start the defragmenter service either.  Odd.
0
 
samiam41Author Commented:
Not sure if this will help but I'm using Windows 7 Enterprise 64bit and Powershell 2.0

I get a similar error when I try to change the service start type so this problem has to relate to a permission issue or some sort of configuration problem.  Thoughts?
0
 
samiam41Author Commented:
I added my domain account to the local admin group, restarted the laptop and tried to change the startup type of another service and get access denied error.

PS C:\MyScripts> set-service -name wwansvc -startupType automatic
Set-Service : Service 'WWAN AutoConfig (wwansvc)' cannot be configured due to t
he following error: Access is denied
At line:1 char:12
+ set-service <<<<  -name wwansvc -startupType automatic
    + CategoryInfo          : PermissionDenied: (System.ServiceProcess.Service
   Controller:ServiceController) [Set-Service], ServiceCommandException
    + FullyQualifiedErrorId : CouldNotSetService,Microsoft.PowerShell.Commands
   .SetServiceCommand
0
 
Seaton007Commented:
Try running your command prompt as administrator by right-clicking on it and selecting Run as administrator, then run the PowerShell command from there.
0
 
samiam41Author Commented:
seaton007, it's solutions like that which make me debate my future and consider becoming a farmer.  That worked!!  It had all the symptoms of a permissions issue but I manually added my user account to the local admin account.  I never even thought to try running it as an administrator.  There goes 4+ hours I will never get back.

Ok, so riddle me this.  Why do I need to use the "run as administrator" option on the command prompt for powershell?  Going forward, is there anyway to set powershell to always "run as the administrator" or is this something I will have to do each and every time I run PS?

Again, thank you, thank you, thank you for putting me out of my misery with this blasted issue experiencing at the beginning of my PS journey.  Should be a great time.
0
 
Seaton007Commented:
You're welcome!  I'm glad we figured out what was going on!

This post and the one right below it seems to explain the cause: http://windows7forums.com/windows-7-support/36990-why-doesnt-local-administrator-group-have-full-administrator-rights.html#post214123
0
 
David Johnson, CD, MVPOwnerCommented:
Anything that affects the MACHINE rather than the user requires running as the administrator.. a service change definitely affects the machine.
0
 
samiam41Author Commented:
So UAC is the culprit (unless I completely summarized the article wrong which is highly possible)?  Ain't that a whoopin'.  

Thanks for the information and the help!
0
 
samiam41Author Commented:
@ve3ofa, thanks for the information.  I completely agree.  I am in the local administrator's group and as I said in the OP, I can start/stop and reconfigure the services from the services.msc snap-in which made no sense why I couldn't do it from PS.  I appreciate the information!
0
 
samiam41Author Commented:
Brilliant.  Simple, effective and to the point.  Looks like I will be learning more than I thought with PS.
0
 
samiam41Author Commented:
UAC "was" the culprit.  I turned it off and suddenly I am given the real keys to castle, not the playskool version.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now