· 8 years ago · May 16, 2018, 06:52 AM
1cls
2
3$inputfilepath = $env:USERPROFILE + "\Desktop"
4$inputfilename = "servers.txt"
5$serverlistinput = $inputfilepath + "\" + $inputfilename
6
7Write-host "Check Input File" -Foregroundcolor Yellow -Backgroundcolor Black
8$checkinputexist = test-path $serverlistinput
9
10if ($checkinputexist -ne $True)
11{
12 Write-host "Please Generate Servers.txt on the desktop. This should contain all the servers you wish to connect to" -Foregroundcolor Red -BackgroundColor Black
13 write-host "One Entry per line" -Foregroundcolor Red -Backgroundcolor Black
14 Exit 1
15}
16cls
17write-host "Input File Exists!" -Foregroundcolor Green -backgroundcolor Black
18
19Write-Host "`nReading in server list, Please wait..." -foregroundcolor Yellow -backgroundcolor Black
20$serverlist = Get-Content $serverlistinput
21if ($serverlist.count -gt 0)
22{
23Write-Host "`nWe have read " $serverlist.count " servers from the file" -Foregroundcolor Green -backgroundcolor Black
24Write-Host "The following servers will be scanned `n" $serverlist -Foregroundcolor Green -backgroundcolor Black
25}
26else
27{
28 cls
29 write-host "Servers.txt is either empty or corrupt please re-create or add server names to the list" -foregroundcolor red -backgroundcolor black
30 exit 1
31}
32
33#test for results directory if does not exist create it!
34
35$resultsdirexist = Test-Path $env:USERPROFILE
36$resultsdirparent = $env:USERPROFILE + "\Desktop"
37$resultsdirname = "EventLog"
38$testpath = $resultsdirparent + "\" + $resultsdirname
39$resultsdirexist = Test-Path $testpath
40
41if ($resultsdirexist -ne "True")
42{
43Write-Host "Directory Does not exist."
44Write-Host "Creating...."
45Set-Location $resultsdirparent
46New-Item -path $resultsdirparent -Name EventLog -type directory
47Write-Host $testpath " has been created"
48Write-Host "This is where all output from the files will be stored"
49}
50
51
52
53$report = $testpath + "\reports.htm"
54Clear-Content $report
55
56[array]$eventlogs = $null
57$eventlogs += "Application"
58$eventlogs += "Security"
59$Eventlogs += "System"
60$countarr = $eventlogs.count
61
62
63
64Foreach ($s in $serverlist)
65{
66 $progress = "."
67
68 Add-Content $report "<html>"
69 Add-Content $report "<head>"
70 Add-Content $report "<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>"
71 Add-Content $report '<title>Event Log Report for Server $s</title>'
72 add-content $report '<STYLE TYPE="text/css">'
73 add-content $report "<!--"
74 add-content $report "td {"
75 add-content $report "font-family: Tahoma;"
76 add-content $report "font-size: 11px;"
77 add-content $report "border-top: 1px solid #999999;"
78 add-content $report "border-right: 1px solid #999999;"
79 add-content $report "border-bottom: 1px solid #999999;"
80 add-content $report "border-left: 1px solid #999999;"
81 add-content $report "padding-top: 0px;"
82 add-content $report "padding-right: 0px;"
83 add-content $report "padding-bottom: 0px;"
84 add-content $report "padding-left: 0px;"
85 add-content $report "}"
86 add-content $report "body {"
87 add-content $report "margin-left: 5px;"
88 add-content $report "margin-top: 5px;"
89 add-content $report "margin-right: 0px;"
90 add-content $report "margin-bottom: 10px;"
91 add-content $report ""
92 add-content $report "table {"
93 add-content $report "border: thin solid #000000;"
94 add-content $report "}"
95 add-content $report "-->"
96 add-content $report "</style>"
97 Add-Content $report "</head>"
98 Add-Content $report "<body>"
99 add-content $report "<table width='100%'>"
100 add-content $report "<tr bgcolor='#CCCCCC'>"
101 add-content $report "<td colspan='7' height='25' align='center'>"
102 add-content $report "<font face='tahoma' color='#003399' size='4'><strong>Event Logs Collection From Server $s</strong></font>"
103 add-content $report "</td>"
104 add-content $report "</tr>"
105 add-content $report "</table>"
106
107 add-content $report "<table width='100%'>"
108 Add-Content $report "<tr bgcolor=#CCCCCC>"
109 Add-Content $report "<td width='20%' align='center'>Index</td>"
110 Add-Content $report "<td width='20%' align='center'>Time</td>"
111 Add-Content $report "<td width='20%' align='center'>EntryType</td>"
112 Add-Content $report "<td width='20%' align='center'>Source</td>"
113 Add-Content $report "<td width='20%' align='center'>InstanceID</td>"
114 Add-Content $report "<td width='20%' align='center'>Message</td>"
115 Add-Content $report "</tr>"
116
117For ($count = 0; $count -lt $countarr;$count++)
118{
119
120 write-host "`n`nCollection Event Logs" $eventlogs[$count] "from Computer $s" -foregroundcolor yellow -backgroundcolor black
121 $logs = get-eventlog -logname $eventlogs[$count] -computername $s
122 Write-host "Processing" -foregroundcolor yellow -backgroundcolor black
123
124 Foreach ($l in $logs)
125 {
126 write-host $progress -nonewline -Foregroundcolor Green -backgroundcolor Black
127 $index = $l.index
128 $time = $l.timegenerated
129 $Entrytype = $l.entrytype
130 $Source = $l.source
131 $InstanceID = $l.instanceID
132 $Message = $l.message
133
134 if ($entrytype -eq "Error")
135 {
136
137 Add-Content $report "<tr>"
138 Add-Content $report "<td bgcolor='#FF0000'>$index</td>"
139 Add-Content $report "<td bgcolor='#FF0000' align=center>$time</td>"
140 Add-Content $report "<td bgcolor='#FF0000' align=center>$entrytype</td>"
141 Add-Content $report "<td bgcolor='#FF0000' align=center>$source</td>"
142 Add-Content $report "<td bgcolor='#FF0000' align=center>$InstanceID</td>"
143 Add-Content $report "<td bgcolor='#FF0000' align=center>$Message</td>"
144 Add-Content $report "</tr>"
145 }
146
147 if ($entrytype -eq "Warning")
148 {
149
150 Add-Content $report "<tr>"
151 Add-Content $report "<td bgcolor='#FFF000'>$index</td>"
152 Add-Content $report "<td bgcolor='#FFF000' align=center>$time</td>"
153 Add-Content $report "<td bgcolor='#FFF000' align=center>$entrytype</td>"
154 Add-Content $report "<td bgcolor='#FFF000' align=center>$source</td>"
155 Add-Content $report "<td bgcolor='#FFF000' align=center>$InstanceID</td>"
156 Add-Content $report "<td bgcolor='#FFF000' align=center>$Message</td>"
157 Add-Content $report "</tr>"
158 }
159
160 if ($entrytype -eq "Information")
161 {
162 Add-Content $report "<tr>"
163 Add-Content $report "<td>$index</td>"
164 Add-Content $report "<td>$time</td>"
165 Add-Content $report "<td>$entrytype</td>"
166 Add-Content $report "<td>$source</td>"
167 Add-Content $report "<td>$InstanceID</td>"
168 Add-Content $report "<td>$Message</td>"
169 Add-Content $report "</tr>"
170 }
171 $progess++
172 }
173Add-content $report "</table>"
174Add-Content $report "</body>"
175Add-Content $report "</html>"
176}
177}