Powershell – Running a script as administrator without login as administrator

file-permissionspermissionspowershell

An old mate of mine used to say "Any question is stupid. Stupid is avoid asking"

I'm pretty new on Windows System Administrator (just 3/4 months) and recently i started working on powershell 2.0.

I'm administering a set of windows services, one of them is going to try to execute a "Start-Service" command as part of a powershell script. This windows service is running under a domain account "ATG\Boot" as part of administrators group.

But, Start-Service/Stop-Service always fails for this reason:

Stop-Service : Service 'SQL Server
Reporting Services (MSSQLSERVER)
(ReportServer)' cannot be stopped due
to the follow ing error: Cannot open
ReportServer service on computer '.'.
At line:1 char:13
+ Stop-Service <<<< Report
+ CategoryInfo : CloseError:
(System.ServiceProcess.ServiceController:ServiceController)
[Stop-Service],
ServiceCommandException
+ FullyQualifiedErrorId : CouldNotStopService,Microsoft.PowerShell.Commands.StopServiceCommand

This error is reproduced when i execute script from shell, but works properly when i run script with "Run as administrator" option.

I would like to empathize that user is part of local administrators group.

Any ideas?

Best Answer

Is the UAC enabled? You probably have to have you script elevate itself. This probably means that your script will display a UAC prompt.

This was the first search hit for 'powershell uac prompt'.

https://stackoverflow.com/questions/1566969/showing-the-uac-prompt-in-powershell-if-the-action-requires-elevation