Share via

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 for business | Windows Server | User experience | Other
0 comments No comments

2 answers

Sort by: Most helpful
  1. Miles 1,286 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.

    Was this answer helpful?

    0 comments No comments

  2. Andreas Baumgarten 132.1K Reputation points MVP Volunteer Moderator
    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

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.