I’ve to collect certain events for sharing it by mail; I’m missing something because the script, take a lot of time for only 2 servers and, the result is absurd!
Server1 events count:
<code> $Etype = @( "Warning", "Error" )
$Source = "Cisco Systems Inc. ICM"
$StartDate = ((Get-Date).AddDays(-2))
$EndDate = Get-Date
(Get-EventLog -LogName Application -After $StartDate -Before $EndDate -EntryType $Etype -Source $Source).Count
}
$rEVT
2576
</code>
<code> $Etype = @( "Warning", "Error" )
$Source = "Cisco Systems Inc. ICM"
$StartDate = ((Get-Date).AddDays(-2))
$EndDate = Get-Date
(Get-EventLog -LogName Application -After $StartDate -Before $EndDate -EntryType $Etype -Source $Source).Count
}
$rEVT
2576
</code>
$Etype = @( "Warning", "Error" )
$Source = "Cisco Systems Inc. ICM"
$StartDate = ((Get-Date).AddDays(-2))
$EndDate = Get-Date
(Get-EventLog -LogName Application -After $StartDate -Before $EndDate -EntryType $Etype -Source $Source).Count
}
$rEVT
2576
Server2 events count:
<code>$rEVT2 = Invoke-Command -ComputerName $Srv2 -scriptblock {
$Etype = @( "Warning", "Error" )
$Source = "Cisco Systems Inc. ICM"
$StartDate = ((Get-Date).AddDays(-2))
$EndDate = Get-Date
(Get-EventLog -LogName Application -After $StartDate -Before $EndDate -EntryType $Etype -Source $Source).Count
}
$rEVT2
3853
</code>
<code>$rEVT2 = Invoke-Command -ComputerName $Srv2 -scriptblock {
$Etype = @( "Warning", "Error" )
$Source = "Cisco Systems Inc. ICM"
$StartDate = ((Get-Date).AddDays(-2))
$EndDate = Get-Date
(Get-EventLog -LogName Application -After $StartDate -Before $EndDate -EntryType $Etype -Source $Source).Count
}
$rEVT2
3853
</code>
$rEVT2 = Invoke-Command -ComputerName $Srv2 -scriptblock {
$Etype = @( "Warning", "Error" )
$Source = "Cisco Systems Inc. ICM"
$StartDate = ((Get-Date).AddDays(-2))
$EndDate = Get-Date
(Get-EventLog -LogName Application -After $StartDate -Before $EndDate -EntryType $Etype -Source $Source).Count
}
$rEVT2
3853
My script:
<code>$HostsTable = @()
foreach ( $Srv in $MyList ) {
$rEVT_ALL = Invoke-Command -ComputerName $Srv -scriptblock {
$Etype = @( "Warning", "Error" )
$Source = "Cisco Systems Inc. ICM"
$StartDate = ((Get-Date).AddDays(-2))
$EndDate = Get-Date
Get-EventLog -LogName Application -After $StartDate -Before $EndDate -EntryType $Etype -Source $Source | Select-Object -Property TimeGenerated, EntryType, Category, Message
}| ForEach-Object {
[PSCustomObject]@{
HN = $Srv
TimeCreated = [DateTime]$_.TimeGenerated
Category = $_.Category
Level = $_.EntryType
Message = $_.Message
}
$HostsTable += $rEVT_ALL
}
}
</code>
<code>$HostsTable = @()
foreach ( $Srv in $MyList ) {
$rEVT_ALL = Invoke-Command -ComputerName $Srv -scriptblock {
$Etype = @( "Warning", "Error" )
$Source = "Cisco Systems Inc. ICM"
$StartDate = ((Get-Date).AddDays(-2))
$EndDate = Get-Date
Get-EventLog -LogName Application -After $StartDate -Before $EndDate -EntryType $Etype -Source $Source | Select-Object -Property TimeGenerated, EntryType, Category, Message
}| ForEach-Object {
[PSCustomObject]@{
HN = $Srv
TimeCreated = [DateTime]$_.TimeGenerated
Category = $_.Category
Level = $_.EntryType
Message = $_.Message
}
$HostsTable += $rEVT_ALL
}
}
</code>
$HostsTable = @()
foreach ( $Srv in $MyList ) {
$rEVT_ALL = Invoke-Command -ComputerName $Srv -scriptblock {
$Etype = @( "Warning", "Error" )
$Source = "Cisco Systems Inc. ICM"
$StartDate = ((Get-Date).AddDays(-2))
$EndDate = Get-Date
Get-EventLog -LogName Application -After $StartDate -Before $EndDate -EntryType $Etype -Source $Source | Select-Object -Property TimeGenerated, EntryType, Category, Message
}| ForEach-Object {
[PSCustomObject]@{
HN = $Srv
TimeCreated = [DateTime]$_.TimeGenerated
Category = $_.Category
Level = $_.EntryType
Message = $_.Message
}
$HostsTable += $rEVT_ALL
}
}
Mesaure command:
<code>(Get-History)[-1].EndExecutionTime - (Get-History)[-1].StartExecutionTime
Days : 0
Hours : 0
Minutes : 18 <--------
Seconds : 35
Milliseconds : 898
Ticks : 11158982764
TotalDays : 0,0129154893101852
TotalHours : 0,309971743444444
TotalMinutes : 18,5983046066667
TotalSeconds : 1115,8982764
TotalMilliseconds : 1115898,2764
</code>
<code>(Get-History)[-1].EndExecutionTime - (Get-History)[-1].StartExecutionTime
Days : 0
Hours : 0
Minutes : 18 <--------
Seconds : 35
Milliseconds : 898
Ticks : 11158982764
TotalDays : 0,0129154893101852
TotalHours : 0,309971743444444
TotalMinutes : 18,5983046066667
TotalSeconds : 1115,8982764
TotalMilliseconds : 1115898,2764
</code>
(Get-History)[-1].EndExecutionTime - (Get-History)[-1].StartExecutionTime
Days : 0
Hours : 0
Minutes : 18 <--------
Seconds : 35
Milliseconds : 898
Ticks : 11158982764
TotalDays : 0,0129154893101852
TotalHours : 0,309971743444444
TotalMinutes : 18,5983046066667
TotalSeconds : 1115,8982764
TotalMilliseconds : 1115898,2764
Result:
<code>$HostsTable.count
10011624 <------ :D
</code>
<code>$HostsTable.count
10011624 <------ :D
</code>
$HostsTable.count
10011624 <------ :D
Please, help me!
Roberto