$utfil = d:\temp\filnamn.csv
Out-File$utfil
$computers=Get-ADComputer-filter*-Propertiesname,operatingsystem,canonicalname,description|Where-Object {$_.operatingsystem -like'*Windows server*'} |Select-Objectname,operatingsystem,canonicalname,description
foreach ( $computerin$computers){
$status=$null
$dns=$null
try {
$dns=Get-WmiObjectWin32_NetworkAdapterConfiguration-ComputerName$computer.name -ErrorActionStop|Where{$_.IPEnabled -eq"TRUE"} |select-object-ExpandPropertydnsserversearchorder
}
catch[System.Exception] {
if($error-like'*Access is denied*'){$status="Access is denied"}
}
$varv=0
$ip1="0"
$ip2="0"
$ip3="0"
foreach ($ipin$dns) {
$varv++
if ($varv-eq1){$ip1=$ip}
if ($varv-eq2){$ip2=$ip}
if ($varv-eq3){$ip3=$ip}
}
Add-Content$utfil"$($computer.name);$ip1;$ip2;$ip3;$status;$($computer.operatingsystem);$($computer.description);$($computer.canonicalname)"
write-host"$($computer.name)$ip1$ip2$ip3$status"
}