Link to home
Start Free TrialLog in
Avatar of TCBob
TCBob

asked on

Powershell - why as administrator?

Hi,
    I am trying to learn the basics of powershell.  I have found what seems like an excellent tutorial but I think am having issues with permissions.

The tutoral I am looking at has been covering using powershell to look at services, an excellent example as it relates to something that many people are familiar with.

Anyway my user profile is a in the local administrator group and also the domain admin group.  I can stop and start sevices use the GUI no problems.  However when I try to stop or start a service in powershell it gives me an error.  Here is an example of the issue - I start by getting the status of the service:

Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS X:\myname\PowerShell\MyScripts> get-service -name bthserv

Status   Name               DisplayName
------   ----               -----------
Stopped  bthserv            Bluetooth Support Service


This is fine but when I try to start the service using PowerShell I get this error:

PS X:\myname\PowerShell\MyScripts> start-service -name bthserv
Start-Service : Service 'Bluetooth Support Service (bthserv)' cannot be started due to the following error: Cannot ope
 bthserv service on computer '.'.
At line:1 char:14
+ start-service <<<<  -name bthserv
    + CategoryInfo          : OpenError: (System.ServiceProcess.ServiceController:ServiceController) [Start-Service],
   ServiceCommandException
    + FullyQualifiedErrorId : CouldNotStartService,Microsoft.PowerShell.Commands.StartServiceCommand

PS X:\myname\PowerShell\MyScripts>


When I run powershell as administrator it works fine.  I guess what I am trying to understand is why as a user I can runs services via the GUI but not PowerShell.

Thanks in Advance
Bob
Avatar of 2Cs
2Cs
Flag of United Kingdom of Great Britain and Northern Ireland image

Right click PowerShell and select 'Run As Administrator'.
Or right click and open the properties of the shortcut (hold shift as well if located on the taskbar), then click Advanced and check the box, run as administrator.

That way the application will always run as administrator and you wont have to right click every time you want to use it.

It is to do with UAC and built-in security for Windows 7, this is meant to stop nasty applications running or executing script without being prompted in the secure desktop to do so first.
Avatar of TCBob
TCBob

ASKER

Hi, thanks for your comment.  I am fine with how to actually run Powershell as administrator, as I said in my original post I know it works when I run powershell as admin.  I was just more interested in why I have to run as admin when I have both local and domain admin rights?
Avatar of Qlemo
Well, if you switch off UAC, you can control services from the shell, too ;-).

The Service applet (services.msc) is run with elevated privileges (if available) automatically, IIRC.
ASKER CERTIFIED SOLUTION
Avatar of ThinkPaper
ThinkPaper
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TCBob

ASKER

Thanks very much for taking the time to explain.  I was just a little confussed as I have admin rights anyway.  Nevermind, no biggie.
Bob
Yeah, it kind of is a pain, especially when you're ALREADY logged on as admin. Our setup requires us to run as admin and then re-enter our admin credentials again (even though we're logged in). If this type of security is too stringent for you, you can definitely turn it off. But if your environment is where security is key, you may want to leave it on.