locked
Get-Service / Service Status > Excel RRS feed

  • Question

  • So this is odd.

    I'm dumping script output to an Excel spreadsheet (done this quite a lot in the last year or two).

    One particular line of code is 

                $Sheet.Cells.Item($count,5) = (Get-Service -Name servicefoo -ComputerName $computer).Status

    If I type "(Get-Service -Name servicefoo -ComputerName <computer name here>).Status" into a powershell command line, I get "Running".  

    What I see when I use the code snippet is that the output to Excel is "4" instead of "Running".  

    I know I can cheat around it by using an "if / then", but I'd like to find out where the loss in translation is between powershell and Excel (i.e., the conversion from a service status to a number).

    Any insights are appreciated, thanks!!

    Ben

    Wednesday, March 23, 2016 1:25 PM

Answers

  • $status = (Get-Service -Name servicefoo -ComputerName $computer).Status

    $Sheet.Cells.Item($count,5) = "$status"


    \_(ツ)_/

    • Marked as answer by BAWrites Wednesday, March 23, 2016 4:22 PM
    Wednesday, March 23, 2016 2:02 PM

All replies

  • $status = (Get-Service -Name servicefoo -ComputerName $computer).Status

    $Sheet.Cells.Item($count,5) = "$status"


    \_(ツ)_/

    • Marked as answer by BAWrites Wednesday, March 23, 2016 4:22 PM
    Wednesday, March 23, 2016 2:02 PM
  • To the rescue as always.  I knew it was something simple - thanks!!

    Wednesday, March 23, 2016 4:22 PM