Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Question about adding to output with PowerShell

Posted on 2013-01-30
3
Medium Priority
?
297 Views
Last Modified: 2013-01-30
Hello. I created a PowerShell script that searches the event viewer for Service Pack information in the event viewer. It reads from a text file and outputs what it finds. I am still learning my way around PowerShell. I want to add the name of each computer before it searches the next to my output.

For example, the output currently looks like the below.

Error Microsoft-Windows-Service Pack Installer          8 Service Pack installation failed with error code 0x800f0828.                      
           Error Microsoft-Windows-Service Pack Installer          5 There is not enough free disk space to install the Service Pack. Required=4623 MB.
     Information Microsoft-Windows-Service Pack Installer          1 Service Pack 1 installation started.                                              
           Error Microsoft-Windows-Service Pack Installer          8 Service Pack installation failed with error code 0x800f0828.                      
     Information Microsoft-Windows-Service Pack Installer          9 Service Pack 1 installation succeeded.                                            
     Information Microsoft-Windows-Service Pack Installer          1 Service Pack 1 installation started.                                              
     Information Microsoft-Windows-Service Pack Installer          1 Service Pack 1 installation started.                                              
     Information Microsoft-Windows-Service Pack Installer          1 Service Pack 1 installation started.                                              

I would like it to look like the below. I assume I could do something with $Computer but I am not sure how to do so.

Computer 1
           Error Microsoft-Windows-Service Pack Installer          8 Service Pack installation failed with error code 0x800f0828.                      
           Error Microsoft-Windows-Service Pack Installer          5 There is not enough free disk space to install the Service Pack. Required=4623 MB.
     Information Microsoft-Windows-Service Pack Installer          1 Service Pack 1 installation started.                                              
           Error Microsoft-Windows-Service Pack Installer          8 Service Pack installation failed with error code 0x800f0828.                      

Computer 2
     Information Microsoft-Windows-Service Pack Installer          9 Service Pack 1 installation succeeded.                                            
     Information Microsoft-Windows-Service Pack Installer          1 Service Pack 1 installation started.                                              
     Information Microsoft-Windows-Service Pack Installer          1 Service Pack 1 installation started.                                              
     Information Microsoft-Windows-Service Pack Installer          1 Service Pack 1 installation started.                                              

I know it is something simple that I am missing but I cannot see to find it. Any help is appreciated.

$Computer = Get-Content c:\temp\machines.txt
If (Test-Connection -comp $computer -count 1 -quiet) {
  "Searching Event Viewer"
   Get-EventLog System -ComputerName $Computer -Newest 4 -Source '*Service Pack*' | Format-Table Time, EntryType, Source, InstanceID, Message -AutoSize | Out-File C:\temp\ServicePack.log
  }
Else {
  "Machine is offline."
   Exit
  }
0
Comment
Question by:Lorrec
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 2000 total points
ID: 38835304
i've added MachineName to the properties exported:

$Computer = Get-Content c:\temp\machines.txt
If (Test-Connection -comp $computer -count 1 -quiet) {
  "Searching Event Viewer"
   Get-EventLog System -ComputerName $Computer -Newest 4 -Source '*Service Pack*' | Format-Table MachineName, Time, EntryType, Source, InstanceID, Message -AutoSize | Out-File C:\temp\ServicePack.log
  }
Else {
  "Machine is offline."
   Exit
  }

Open in new window

0
 

Author Comment

by:Lorrec
ID: 38835347
Wow. It was simple. Thank you for the assistance.
0
 

Author Closing Comment

by:Lorrec
ID: 38835351
Thank you for the quick response.
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Utilizing an array to gracefully append to a list of EmailAddresses
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question