Archive for category Cisco
Export to Excel – Ping Status
Posted by admin in Cisco, Powershell on September 30, 2009
Here is a modified version of my previous post. This takes Win32_PingStatus, pings a subnet, and writes the output to Excel. All using Powershell.
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #
# Powershell: Export Ping Status to Excel
# Exports pings of address range to excel
# Yattaa.com 9/28/09
$erroractionpreference = "SilentlyContinue"
$a = New-Object -comobject Excel.Application
$a.visible = $True
$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)
$c.Cells.Item(1,1) = "Host"
$c.Cells.Item(1,2) = "Response"
$c.Cells.Item(1,3) = "Return Time"
($c.UsedRange).Interior.ColorIndex = 36
($c.UsedRange).Font.ColorIndex = 1
($c.UsedRange).Font.Bold = $True
$intRow = 2
$i = 0
while ($i -lt 255){
$i += 1
$a = get-WmiObject "Win32_PingStatus" -filter "Address='192.168.1.$i' and Timeout=100"
Write-Host $a.Address, $a.statuscode
$c.Cells.Item($intRow,1) = $a.Address
$c.Cells.Item($intRow,2) = $a.StatusCode
If($a.StatusCode -eq 0){
$c.Cells.Item($intRow,2).Interior.ColorIndex = 4
$c.Cells.Item($intRow,3) = $a.ResponseTimeToLive
}
Else{
$c.Cells.Item($intRow,2).Interior.ColorIndex = 3
}
$intRow = $intRow + 1
}
($c.UsedRange).EntireColumn.AutoFit() |