4

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?

2

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

| improve this answer | |
0

Here's a script I use to stop SQL Server service. By using start-process with the -runas switch a separate PowerShell process will be started as admin. You will be prompted for UAC.

Start-Process powershell.exe -argumentlist '-noprofile -command get-service -Name "MSSQL`$R2" | ? {$_.Status -eq "Running"} | Stop-Service -Force' -verb runas

I have blog post here about this subject.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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