Jump to content

Test connectivity to alert when a pc comes online


Recommended Posts

Posted

Hi there I would like a script to let me know when certain pc's are online.

I've got the following script that will let me know if a pc is online or not. But ideally I would like this to run in the back ground and then possibly a popup to tell me that the pc is now online?

 

Anyone able to help

Thanks in advance

Nick

 

 

 

$ComputerName= "PCname"

If (Test-Connection -ComputerName $computer -Count 1 -Quiet)

{

Write-Host "$computer is Online"

 

} else {

Write-Host "$computer is offline"

 

}

Posted

while ($true)
{
   $ComputerName= "facebook"
   If (Test-Connection -ComputerName $ComputerName -Count 1 -Quiet)
   {
       Write-Host "$ComputerName is Online"
   }
   else
   {
       Write-Host "$ComputerName is offline"
   }
   Start-Sleep 10
}

That will continue looping forever, and check every 10 seconds.

 

while ($true)
{
   $ComputerName= "facebook"
   If (Test-Connection -ComputerName $ComputerName -Count 1 -Quiet)
   {
       Write-Host "$ComputerName is Online"
       break
   }
   else
   {
       Write-Host "$ComputerName is offline"
   }
   Start-Sleep 10
}

That will loop until it's online, then stop.

Posted

Taking that one step further, this will loop until it's online and then pop up a message box saying when it came back online, then stop

while ($true)
{
   $ComputerName= "facebook"
   If (Test-Connection -ComputerName $ComputerName -Count 1 -Quiet)
   {
       $DT = get-date -format HH:mm
       Start-Job -ScriptBlock{[system.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms");[system.Windows.Forms.MessageBox]::Show("Computer $using:computername came back online at $using:DT", "Online Notification")}
       #Write-Host "$ComputerName is Online"
       break
   }
   else
   {
       #Write-Host "$ComputerName is offline"
   }
   Start-Sleep 10
}

  • Thanks 1
Posted (edited)

$csv = Import-Csv n:\computers.csv

$done = @()

while ($true)
{
   $csv | ForEach {
       $ComputerName = $_.PC
       if ($done.Contains($computername) -eq $false)
       {
           If (Test-Connection -ComputerName $ComputerName -Count 1 -Quiet)
           {
               $DT = Get-Date -Format HH:mm
               Start-Job -ScriptBlock{[system.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms");[system.Windows.Forms.MessageBox]::Show("Computer $using:computername came back online at $using:DT", "Online Notification")}
               $done += $ComputerName
               #Write-Host "$ComputerName is Online"
               #break
           }
           else
           {
               #Write-Host "$ComputerName is offline"
           }
       }
   }
   Start-Sleep 10
}

CSV called computers.csv with a header line of "PC" eg:

 

PC

facebook

off-netman

standby-01

standby-02

Edited by howartp
Missed initialising empty array
  • Thanks 1
Posted

VBS with this in, just enter relevant details and then place in startup folder:

 

Set objMail = CreateObject("CDO.Message")

Set objConf = CreateObject("CDO.Configuration")

Set objFlds = objConf.Fields

objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'cdoSendUsingPort

objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "MAILSERVER" 'your smtp server domain or IP address goes here

objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 'default port for email

'uncomment next three lines if you need to use SMTP Authorization

objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "USERNAME"

objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "PASSWORD"

objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'cdoBasic

objFlds.Update

objMail.Configuration = objConf

'objMail.FromName = "e.g.server_name"

objMail.From = "FROMADDRESS"

objMail.To = "TOADDRESS"

objMail.Subject = "Login Notification from my PC"

objMail.TextBody = "PC has been logged in"

objMail.Send

Set objFlds = Nothing

Set objConf = Nothing

Set objMail = Nothing

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...