how do i get a 4th column displaying the servername

Christopher Ellis 1 Reputation point
2021-07-08T12:11:24.237+00:00

mY script is simple i get the servers names from a text file $servers = Get-Content c:\temp\servers.txti am only displaying Status, Name, and Display

here is my script

Status Name DisplayName


Running spooler Print Spooler
Running spooler Print Spooler
Running spooler Print Spooler
Running spooler Print Spooler
Running spooler Print Spooler
Running spooler Print Spooler
Running spooler Print Spooler
Running spooler Print Spoole

How do i make the servers appear in the report as a 4th column?

I know tthat t i am extracting the servers from a text file

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,124 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. MotoX80 31,571 Reputation points
    2021-07-08T13:20:17.507+00:00

    here is my script

    You forgot to include your script.

    $servers = Get-Content c:\temp\servers.txt
    foreach ($srv in $servers) {
        $out = "Something to display."
        "{0} - {1}" -f $out, $srv
    } 
    
    0 comments No comments

  2. Michael Taylor 48,046 Reputation points
    2021-07-08T13:21:29.433+00:00

    You didn't post your script, just what looks like some output. You also didn't specify what $servers contains (e.g. server names, contents of some program output, etc).

    Just completely taking a guess that you are getting a list of servers from some file, then calling some PS function to get the status of spooler on that server using something like Get-Service. You want to combine these into a table output. The key is how you're getting the service status. Get-Service in PS 5 can be used but PS Core removed support for remote computers.

    $servers = Get-Content 'c:\temp\servers.txt'
    Get-Service -ComputerName $servers -Name spooler | Select-Object -Property Status, Name, DisplayName, MachineName
    
    0 comments No comments

  3. Andreas Baumgarten 96,361 Reputation points MVP
    2021-07-08T13:46:07.013+00:00

    Hi @Christopher Ellis ,

    this is the third time you asked the same question within the last days. Your second time question is deleted now.
    But the first time question with an answer is still there: https://learn.microsoft.com/en-us/answers/questions/466305/how-do-i-add-the-servers-queried-in-4th-colunmn-wh.html

    I don't see the reason why repeating the same question again and again is helpful.

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments

  4. Percival Yang 721 Reputation points
    2021-07-09T03:06:50.283+00:00

    Hi
    Please do not post the same question on the forum, for we will keep following up your question until solving it.

    0 comments No comments