Posted in
Windows Powershell,
Windows Server |
No Comment | 5,362 views | 05/06/2013 11:20
You can export HP’s IML logs via PowerShell. Execute PowerShell console with Administrative privileges and run:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
| $Hostname = $env:COMPUTERNAME
&"C:\Program Files\Compaq\Cpqimlv\cpqimlv.exe" /export:C:\test.iml /m:$Hostname
$Logs = Get-Content "C:\test.iml" | Select-String Critical,Caution
Foreach ($Log in $Logs)
{
$ErrorDesc = $Log.Line.Split('"')[1]
if ($ErrorDesc)
{
$ErrorType = $Log.Line.Split(",")[-4]
$ErrorDate = $Log.Line.Split(",")[-1]
}
if ($ErrorType -eq "Critical")
{
Write-Host "Description: $ErrorDesc" -ForegroundColor Red
Write-Host "Type: $ErrorType" -ForegroundColor Red
Write-Host "Date: $ErrorDate" -ForegroundColor Red
Write-Host " "
}
else
{
Write-Host "Description: $ErrorDesc" -ForegroundColor Yellow
Write-Host "Type: $ErrorType" -ForegroundColor Yellow
Write-Host "Date: $ErrorDate" -ForegroundColor Yellow
Write-Host " "
}
} |
$Hostname = $env:COMPUTERNAME
&"C:\Program Files\Compaq\Cpqimlv\cpqimlv.exe" /export:C:\test.iml /m:$Hostname
$Logs = Get-Content "C:\test.iml" | Select-String Critical,Caution
Foreach ($Log in $Logs)
{
$ErrorDesc = $Log.Line.Split('"')[1]
if ($ErrorDesc)
{
$ErrorType = $Log.Line.Split(",")[-4]
$ErrorDate = $Log.Line.Split(",")[-1]
}
if ($ErrorType -eq "Critical")
{
Write-Host "Description: $ErrorDesc" -ForegroundColor Red
Write-Host "Type: $ErrorType" -ForegroundColor Red
Write-Host "Date: $ErrorDate" -ForegroundColor Red
Write-Host " "
}
else
{
Write-Host "Description: $ErrorDesc" -ForegroundColor Yellow
Write-Host "Type: $ErrorType" -ForegroundColor Yellow
Write-Host "Date: $ErrorDate" -ForegroundColor Yellow
Write-Host " "
}
}
You can also write them into event viewer after parsing. If you need to get specific date, change script like this:
1
2
3
4
5
6
7
| $Date = Get-Date
$Day = $Date.Day
$Month = $Date.Month
$Year = $Date.Year
$Hostname = $env:COMPUTERNAME
&"C:\Program Files\Compaq\Cpqimlv\cpqimlv.exe" /export:C:\test.iml /m:$Hostname
$Logs = Get-Content "C:\test.iml" | Select-String Critical,Caution | Select-String $Month/$Day/$Year |
$Date = Get-Date
$Day = $Date.Day
$Month = $Date.Month
$Year = $Date.Year
$Hostname = $env:COMPUTERNAME
&"C:\Program Files\Compaq\Cpqimlv\cpqimlv.exe" /export:C:\test.iml /m:$Hostname
$Logs = Get-Content "C:\test.iml" | Select-String Critical,Caution | Select-String $Month/$Day/$Year
So you can always get new Critical and Caution logs.