Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

Test-Connection and email results

$
0
0

OK, I'm hoping Bob or Martin can help me with this as I've seen a lot of their posts with positive results (Including modification of some of my scripts).

I am trying to query AD for every server in the domain (It's a single domain with no child domains).  I then want to test-connection of each server.  I want to take the number of Servers and the Servers not responding to test-connection and use them as the subject of the email.  My script is as follows and gives no output. 

 

$Computers = Get-ADComputer -Filter * -Properties OperatingSystem | where OperatingSystem -Like *server* | select Name

$Count = $Computers.Count

$Connection = Test-Connection -ComputerName $Computer.Name -Count 1 -Quiet

$Results = @()

foreach ($Computer in $Computers) {

$Results += 

Write-Verbose $Computer.Name

if

($Connection -eq 'True')

{out-null}

else

                {

                {[PSCustomObject]@{

                        Server = $computer.Name

                                                }

Send-MailMessage -From mine@mydomain.com -to mine@mydomain.com -Subject "$results Offline $Count Servers Total" -SmtpServer mine@mydomain.com}

                 }

                                                        }

 

Also, I've seen some replies on this site that have been color coded as it looks in the ISE, if someone could tell me how to do that, I think it'd be helpful for the future.

 

I would have been happy to use someone else's script for this purpose although I haven't found one.

As always, any help or suggestions are appreciated.

Thanks everyone.

 


Viewing all articles
Browse latest Browse all 8583

Trending Articles