I wrote a script to get the 10 most recent entries in the Windows application log. It works
fine, but I would prefer to format the output differently.
The output looks like this:
server1\
Count Name
----- ----
9 1008
1 1010
server 2\
Count Name
----- ----
5 256
5 258
I'd like it to look like this.
Server Count Name
------ ----- ----
server1 9 1008
server1 1 1010
Server Count Name
------ ----- ----
server2 5 256
server2 5 258Ideally, the server name would only appear once per group, but I'd settle for what I showed above.
Where does the "\" after the server name come from? Why are there all those empty lines between server groups?
$S = get-content -Path c:\scripts\PowerShell\servers.txt Foreach ($Server in $S) { if (test-connection $server -quiet -TimeToLive 5 -Count 2) { $events = get-WinEvent -ComputerName $Server -logname application -Maxevents 10 -ErrorAction silentlyContinue $output1 = $events | group-object -property Id -noelement | sort-object -property count -descending -ErrorAction silentlyContinue $output2 = Out-String -InputObject $output1 -Width 100 join-path $Server $output2 } else {"Could not connect to " + $Server} }
Thanks,
Matthew
↧
concatenate a string with the results of group-object
↧