I have a script to query all the servers in AD
Import-Module active*
$rtn = $null
Get-ADComputer -Filter {operatingsystem -like "*server*"} |
ForEach-Object {
$rtn = Test-Connection -CN $_.dnshostname -Count 1 -BufferSize 16 -Quiet
IF($rtn -match 'True') {write-host -ForegroundColor green $_.dnshostname}
I want to make the output a variable
Easy way would be:
$Servers = Get-ADComputer -Filter {operatingsystem -like "*server*"}Problem is this would waist time waiting for queries against disabled/powered off machines to error out
I don't know how to use if statements in variables