Here’s the scenario. I’ve created a script to ping a CSV of servers and alert which servers are offline. Normally, I have it pull the list from my desktop, but we use a shared IT notebook that i’ve imported the CSV into that I’d like it to pull from instead since we’re constantly updating server information.
Here’s what I have so far:
While($True)
{
try
{
$ServerList = Import-Csv -Path C:\users\AlertPC\desktop\ip.csv -Header “Name”,“Description”,“Ipaddress”
foreach ($s in $ServerList) {
If (!(Test-Connection -ComputerName $s.Name -Quiet -Count 1)) {
Write-Host -foregroundcolor “green” “$PCName went Offline on $date”
[Console]::Beep(800,1000)
$date = Get-Date -format F
$PCName = $s.Name
$PCDescription = $s.Description
$PCIpaddress = $s.Ipaddress
$msSam = New-Object -ComObject SAPI.SPVoice
$msSam.Speak(“$PCDescription went offline”)
}
}
}
catch
{
Write-Host -foregroundcolor “red” “Double-check your code. Something broke.”
}
Start-Sleep -Seconds 5
}