question

ChristopherEllis-1514 avatar image
0 Votes"
ChristopherEllis-1514 asked Miles-MSFT answered

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

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
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered

Hi @ChristopherEllis-1514 ,

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

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Miles-MSFT avatar image
0 Votes"
Miles-MSFT answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.