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:
$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:
$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:
$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:
(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:
$HostsTable.count
10011624 <------ :D
$HostsTable | select -First 1
HN : SRV1 <--------
TimeCreated : 18/06/2024 19:10:56
Category : Message Delivery
Level : Error
Message : Client: clgr, state transfer operation aborted.
$HostsTable | select -Last 1
HN : SRV1 <--------
TimeCreated : 16/06/2024 19:55:43
Category : Call Router
Level : Error
Message : PG has reported that peripheral: CC_VRU_1 (ID: 5001) is not operational.
After, I've to export-excel, but at the moment something goes wrong...
Please, help me! Roberto
$MyList?$myList = @("SRV1", "SRV2")