Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get-Service and Status

13 views
Skip to first unread message

OldDog

unread,
Jun 2, 2010, 3:54:04 PM6/2/10
to
Hi,

I fi I run:

$B = Get-Service -DisplayName "Opsware Agent" -ComputerName testserver

And then $B, I get this:

PS Scripts:\> $B

Status Name DisplayName
------ ---- -----------
Running OpswareAgent Opsware Agent

And if I type $B.Status

PS Scripts:\> $B.status
Running

BUT! if I put it in a script like this:

$B = Get-Service -DisplayName "Opsware Agent" -ComputerName
$strComputer
$WS.cells.item($rRow, 6) = $B.DisplayName
$WS.cells.item($rRow, 7) = $B.Status

Status comes out as the number 4.

How can I get it to say Running? or failing that what does the 4 mean
and where can I find that out?

OldDog

unread,
Jun 2, 2010, 3:58:12 PM6/2/10
to

I tried this: $WS.cells.item($rRow, 7) = $B.Status.toString() and
it worked. Go figure.

Larry__Weiss

unread,
Jun 2, 2010, 4:10:04 PM6/2/10
to

Try

$WS.cells.item($rRow, 7) = [string]($B.Status)

- Larry

Larry__Weiss

unread,
Jun 2, 2010, 4:24:24 PM6/2/10
to

If you suspect that something has a type of string but it doesn't seem
so, try executing

$B.status.Gettype()

and you'll quickly find out what type it actually is.

In this case:

PS C:> $B.status.Gettype()

IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True ServiceControllerStatus System.Enum

The convenience of implicit casts to [string] on output
to the console can mislead you.

- Larry

PaulChavez

unread,
Jun 2, 2010, 4:48:32 PM6/2/10
to
If you run the output of get-service through get-member you'll see the Status
property is System.ServiceProcess.ServiceControllerStatus which is an
enumeration. The reason it gets auto converted to a string in an interactive
session is due to the implicit out-default (or perhaps it's just the
formatting engine, not really sure).

-Paul


"OldDog" wrote:

> .
>

0 new messages