Solved

Powershell - why as administrator?

Posted on 2012-04-03
7
1,282 Views
Last Modified: 2012-04-18
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
0
Comment
Question by:TCBob
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 5

Expert Comment

by:2Cs
ID: 37800416
Right click PowerShell and select 'Run As Administrator'.
0
 
LVL 5

Expert Comment

by:2Cs
ID: 37800422
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.
0
 

Author Comment

by:TCBob
ID: 37800706
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?
0
Independent Software Vendors: 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!

 
LVL 70

Expert Comment

by:Qlemo
ID: 37849363
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.
0
 
LVL 16

Accepted Solution

by:
ThinkPaper earned 500 total points
ID: 37858146
TCBob - that's because UAC is enabled on your machine. So if you try to run anything that requires elevated privileges (i.e. any of the administrative tools or run some admin stuff through command line) it will require that you run as admin. That's simply how it works. It's an additional security measure to prevent the wrong people from running administrative services.

That's how it is at my work.. I have to "run as administrator" anytime I need to run elevated services (i.e. active directory, exchange management console, powershell, computer management, etc..)

If that annoys you, you can turn UAC off.
0
 

Author Closing Comment

by:TCBob
ID: 37860528
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
0
 
LVL 16

Expert Comment

by:ThinkPaper
ID: 37861621
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.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question