Link to home
Start Free TrialLog in
Avatar of Mike
MikeFlag for United States of America

asked on

Getting "Access is denied" when excuting powershell script.

I attempting to create a power shell script to stop and start a service on stand alone server (.i.e not part a AD domain) but I keep getting the following error "Get-WmiObject : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) . I checked and the RPC is running but it does not allow me to change the services status... Does anybody have an idea what I am missing.
$computername = "ServeName"
$service = "ServiceName"

 
(gwmi win32_service -computername $computername -filter "name='$service'").stopservice()  
 
and
 
 (gwmi win32_service -computername $computername -filter "name='$service'").startservice()

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of the_endjinn
the_endjinn
Flag of United Kingdom of Great Britain and Northern Ireland 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 Mike

ASKER

Thanks that worked.....