how do i add the servers queried in 4th colunmn which we do not have

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

I would like to see the server name show up in the 4th column whuch we currently do not have

$servers = Get-Content c:\temp\servers.txt
foreach ($server in $servers) {get-service -name spooler}

I would like to see the server nameshow up in the 4th column whuch we currently do not have

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 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 Spooler
Running spooler Print Spooler
Running spooler Print Spooler
Running spooler Print Spooler

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

2 answers

Sort by: Most helpful
  1. Andreas Baumgarten 95,496 Reputation points MVP
    2021-07-07T12:19:29.267+00:00

    Hi @Christopher Ellis ,

    you can try this please:

    $servers = Get-Content c:\temp\servers.txt  
    foreach ($server in $servers) {get-service -name spooler | select Name, DisplayName, Status, MachineName}   
    

    ----------

    (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

  2. Miles 1,251 Reputation points
    2021-07-08T06:25:13.267+00:00

    Hi

    We could try to use this :
    $Results = Foreach ($Server in (get-content "C:\Temp\servers.txt"))

    {Get-Service "Windows Event Log" -ComputerName $Server | Select @{Name="Server";Expression={$Server}},Name,Status,DisplayName}

    $Results | Select Server,Name,Status,DisplayName | Out-File "c:\temp\EventLog.txt

    Here is the similar case which we could refer to
    https://community.idera.com/database-tools/powershell/ask_the_experts/f/learn_powershell_from_don_jones-24/14626/add-computer-name-to-output

    Best Regards
    Please note: Information posted in the given link is hosted by a third party. Microsoft does not guarantee the accuracy and effectiveness of information.

    0 comments No comments