Hi everyone
I have script that is scanning my DC for new servers that has been added to my domain + sending an email with the Name, IP and OS of the new server.
What I am looking, is how can i add a line to this script that will check if those new servers has specific Service running on them?
The output that I’m receiving to the email now is:
Dear IT Team,
Weekly AD scan for new servers:
Name IPv4Address OperatingSystem
testsrv x.x.x.x Windows Server 2016 Standard
So i want somehow to add here a “Service” tab that will say “Servicename” running or no, in those servers.
The script:
#> “Start: “+ (Get-Date) try { $domain=”” if ($domain -eq””) { $domain = Get-ADDomain } else { $domain = Get-ADDomain -Identity $domain } $domain_name=$domain.name $distinguished_name = $domain.DistinguishedName $domain_controller = (Get-ADDomainController -server $domain_name).HostName $logging_level=1 $search_base = “OU=my-ous,” + $distinguished_name $days_to_search =-300 # this value needs to be negative integer if ($days_to_search -ge 0) {throw “Value for variable $days_to_search must be a negative integer in days.”} $date_filter = (get-date).adddays($days_to_search) $computers=get-adcomputer -SearchBase $search_base -Properties * -Filter {Created -gt $date_filter -and operatingsystem -like “*windows*”} -server $domain_controller $computers | Select-Object Name, Created,DistinguishedName,IPv4Address,OperatingSystem | ft -AutoSize } Catch { “Error occurred: ” + (Get-Date) throw } $Body = @” <html> <body> <p>Dear Team, <br/> <p>Weekly scan for new servers:</p> $($computers | ConvertTo-Html -Property Name,IPv4Address,OperatingSystem) <br/> </body> </html> “@ Send-MailMessage -To “myemail@test.com” -From ‘do_not_reply@test.com’ -Subject ‘New Servers’ -Body $Body -SmtpServer ‘mysmtp server’ -BodyAsHtml -Priority High