Avatar of Alex Young
Alex YoungFlag for United Kingdom of Great Britain and Northern Ireland asked on

Ping Router Script

Hi,

I am trying to get a Powershell script to ping out - now it works just writing to the console perfectly but trying to get it on a html file is it bit tricky.

$list = get-content "C:\Remote\ip.txt" 


foreach ($ip in $list)

{
$result = New-Object psObject
Write-Host "Trying $($ip)" -ForegroundColor White

Try {

$IPComputer = Test-Connection $ip -Count 1 -ErrorAction Stop | Select -ExpandProperty ipv4Address | `
Select -ExpandProperty ipAddressToString

$Sucess = Write-Host "Success" -ForegroundColor Green

Add-Content $IndexPage "<tr><td>$IP</td><td>$Sucess</td><td>$Failed</td><tr></table>"

}

catch

{

$Failed = Write-Host "Down" -ForegroundColor Red



}

}


$Date = Get-Date -Format "dddd dd MMMM yyyy"
$Time = Get-Date -Format "hh:mm:ss"

$IndexPage = "C:\Remote\Index.html" # This Creates The Index Page
New-Item -ItemType file $IndexPage -Force # Creates The Page

Add-Content $IndexPage "<table width='auto' align='center' border-collapse='collapse'>"
Add-Content $IndexPage "<tr bgcolor='#D0E6FF'>"
Add-Content $IndexPage "<td colspan='4' height='25' align='center'>"
Add-Content $IndexPage "<font face='tahoma' color='#000000' size='2'><b>Router Checker</b></font><BR>"
Add-Content $IndexPage "<font face='Arial' color='#000000' size='2'><b>Date: $Date</b><BR>"
Add-Content $IndexPage "<font face='Arial' color='#00000' size='2'><b>Time: $Time</b>"
Add-Content $IndexPage "</td>"
Add-Content $IndexPage "</tr>"
Add-Content $IndexPage "</table>"

Add-Content $IndexPage '<table id="main" class="sortable" <width="auto" align="center">'
Add-Content $IndexPage "<tr bgcolor='#D0E6FF'>"
#Add-Content $IndexPage "<td width='auto' align='center'>Client</td>"
Add-Content $IndexPage "<td width='auto' align='center'>IP Address</td>"
Add-Content $IndexPage "<td width='auto' align='center'>Up</td>"
Add-Content $IndexPage "<td width='auto' align='center'>Down</td>"
Add-Content $IndexPage "</tr>"

Open in new window


Can anyone suggest what i might be doing wrong at the moment?
Powershell

Avatar of undefined
Last Comment
Alex Young

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Subash Sundharan

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Alex Young

Brilliant Perfect!
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck