Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - exception calling .net object

Reply
 
Old 06-23-2008   #1 (permalink)
Rajeev


 
 

exception calling .net object

Hi,

i'm trying to script management of services on remote computers.
Below is my script,

Exception calling "GetServices" with "1" argument(s): "Cannot open
Service Control Manager on computer 'localhost'. This operation might
require other privileges."
At line 5, position 64
$LOADSVC=[System.ServiceProcess.ServiceController]::GetServices($Server)
..

My System SpecsSystem Spec
Old 06-23-2008   #2 (permalink)
Rajeev


 
 

Re: exception calling .net object

Hi,

i'm trying to script management of services on remote computers.
Below is my script,

Exception calling "GetServices" with "1" argument(s): "Cannot open
Service Control Manager on computer 'localhost'. This operation might
require other privileges."
At line 5, position 64
$LOADSVC=[System.ServiceProcess.ServiceController]::GetServices($Server)
..
..
..
..
..

when i run the script I'm getting the below error
Exception calling "GetServices" with "1" argument(s): "Cannot open
Service Control Manager on computer 'localhost'. This operation might
require other privileges."
At line 5, position 64
$LOADSVC=[System.ServiceProcess.ServiceController]::GetServices($Server)


Could anyone help me on this.. not sure where and how to define the
object.

thanks
My System SpecsSystem Spec
Old 06-23-2008   #3 (permalink)
Rajeev


 
 

Re: exception calling .net object

I'm sorry... my script would be the below one,

$Services=get-content “c:\Services.txt”
$Servers=get-content “c:\Servers.txt”
ForEach($Server in $Servers) {
$LOADSVC=[System.ServiceProcess.ServiceController]::GetServices($Server)
.
.
.
.
please help
My System SpecsSystem Spec
Old 06-23-2008   #4 (permalink)
Marco Shaw [MVP]


 
 

Re: exception calling .net object

Rajeev wrote:
Quote:

> I'm sorry... my script would be the below one,
>
> $Services=get-content “c:\Services.txt”
> $Servers=get-content “c:\Servers.txt”
> ForEach($Server in $Servers) {
> $LOADSVC=[System.ServiceProcess.ServiceController]::GetServices($Server)
> .
> .
> .
> .
> please help
Seems this needs the *IP Address* of the computer, and not the hostname.

[System.ServiceProcess.ServiceController]::GetServices("127.0.0.1")<--WORKS
[System.ServiceProcess.ServiceController]::GetServices("localhost")<--FAILS

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 06-23-2008   #5 (permalink)
Rajeev


 
 

Re: exception calling .net object

Thanks, that works fine. Is there another way where i can use the host
name and manage services?
My System SpecsSystem Spec
Old 06-23-2008   #6 (permalink)
Marco Shaw [MVP]


 
 

Re: exception calling .net object

Rajeev wrote:
Quote:

> Thanks, that works fine. Is there another way where i can use the host
> name and manage services?
Are all your IPs and hostnames in the DNS? You can lookup the IP and
use that, if only temporarily in the script.

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 06-23-2008   #7 (permalink)
Oisin (x0n) Grehan [MVP]


 
 

Re: exception calling .net object

On Jun 23, 2:52*pm, Rajeev <s.raje...@xxxxxx> wrote:
Quote:

> Thanks, that works fine. Is there another way where i can use the host
> name and manage services?
Powershell actually has some cmdlets built in that can manage local
and remote services:

get-service -computer <remotemachine>

or

get-service

(for localhost)

hope this helps,

- Oisin

My System SpecsSystem Spec
Old 06-24-2008   #8 (permalink)
Marco Shaw [MVP]


 
 

Re: exception calling .net object

Oisin (x0n) Grehan [MVP] wrote:
Quote:

> On Jun 23, 2:52 pm, Rajeev <s.raje...@xxxxxx> wrote:
Quote:

>> Thanks, that works fine. Is there another way where i can use the host
>> name and manage services?
>
> Powershell actually has some cmdlets built in that can manage local
> and remote services:
>
> get-service -computer <remotemachine>
NOTE: get-service -computer only works with the v2 CTP. Might actually
be in CTP2 also (I don't have the two running at this time to check).

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Object cast exception at runtime .NET General
Exception calling "CreateInstance" with "2" argument(s): for Microsoft.Update.UpdateColl PowerShell
Problem calling interface of .NET Remoted object via Powershell PowerShell
exception when calling a method: object is read-only PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46