question

TXPJL avatar image
TXPJL asked

Powershell results not showing different Server names

Hi there, I'm not a developer, but I'm trying to get into Powershell to scan logs from a list of servers (event and SQL error logs) and insert them into an SQL Server table. The command is similar to one on www.simple-talk.com is as follows: Get-EventLog -ComputerName (Get-Content 'c:\temp\ Servers.txt') -LogName Application ` -EntryType 'Error','Warning','Information' -Source '*MOVE*','*sql*' -After ((Get-Date).adddays(-1)) How do I display the server names in the results? would like to insert these results into an SQL table, but that's another issue. Thanks
tablepowershell
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
Shawn_Melton avatar image
Shawn_Melton answered
You will need to pipe the command to `Select-Object` and one of the properties will be "MachineName". This should be the value of the server, but obviously in cluster scenario it would likely be the node name so you could see data from both servers. If you want to include the server name as it was passed in from your file, you would need to change your code around a little. $serverList = Get-Content 'C:\temp\ Servers.txt' foreach ($s in $serverList) { Get-EventLog -ComputerName $s -LogName.... | select @{Label="ServerName";Expression={$s}}, MachineName, EventID.... }
1 comment
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Thanks for that. I got it to work for me. Going to try sending this output to an SQL table. I might be back!
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.