Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Service Status

Status
Not open for further replies.

Shift838

IS-IT--Management
Jan 27, 2003
987
0
0
US
I am trying to query a service to get it's state (running, stopped, etc). I am dumping it to a CSV file.

There may be an easier way to do this.

I have it working but when it dumps to the CSV file for status I see:

@{Status=Running}

I just want to see 'Running'.

I thought that I could just trim like I would any string but not the case.

I created a test program of:

Code:
$svcIMA = Get-Service IMAService -ComputerName SERVER01 | Select-Object Status
$IMAtrim = $trimtest.TrimStart("@{Status=")
$IMAResult = $IMAtrim.TrimEnd("}")
Write-Host $imaresult

When I run it I get:

Method invocation failed because
[Selected.System.ServiceProcess.ServiceController] does not contain a method
named 'TrimStart'.
At C:\scripting\trimtest.ps1:6 char:1
+ $IMAtrim = $trimtest.TrimStart("@{Status=")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (TrimStart:String) [], Runtime
Exception
+ FullyQualifiedErrorId : MethodNotFound

Any ideas anyone ?
 
Try this:

Code:
$svcIMA = Get-Service IMAService -ComputerName SERVER01 | Select-Object Status
$status_start = $svcIMA.IndexOf("=") + 1
$status_end = $svcIMA.length - 1
$IMAResult = $svcIMA.substring($status_start,($status_end-$status_start))


Light travels faster than sound. That's why some people appear bright until you hear them speak.
 
Hi can you just do this;

Code:
$svcIMA = Get-Service spooler | Select-Object Status
$svcIMA.Status

Running
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top