Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

How can I turn this output into a variable

$
0
0

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





Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>