Ying Li at myITforum.com

PowerShell & System Center

PowerShell script to ping a list of servers - .NET way

$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) = "Machine Name"
$c.Cells.Item(1,2) = "Ping Status"

$d = $c.UsedRange
$d.Interior.ColorIndex = 19
$d.Font.ColorIndex = 11
$d.Font.Bold = $True
$d.EntireColumn.AutoFit($True)

$intRow = 2

$colComputers = get-content C:\Myworkplace\Clientlist1.txt
foreach ($strComputer in $colComputers)
{
$c.Cells.Item($intRow, 1) = $strComputer.ToUpper()

# This is the key part

$ping = new-object System.Net.NetworkInformation.Ping
$Reply = $ping.send($strComputer)
if ($Reply.status –eq “Success”)
{
$c.Cells.Item($intRow, 2) = “Online”
}
else
{
$c.Cells.Item($intRow, 2) = "Offline"
}
$Reply = ""


$intRow = $intRow + 1

}
$d.EntireColumn.AutoFit()

Posted: Aug 22 2007, 03:19 PM by yli628 | with 2 comment(s)
Filed under:

Comments

MaxGXL Benefits of Glutathione » MaxGXL Glutathione said:

For those over the age of 45, we recommend that they have their blood fat levels tested on a regular basis as part of their general health management. If your reading is above 6. 5 mmol/ L, your risk of heart disease is about four times greater than of

# March 29, 2008 3:57 AM

Weight loss said:

Diet Products and Weight Loss Supplements at Discount Prices. Save 50-70% on quality products.

# May 28, 2008 7:25 AM