PowerShell | Get DNS Settings on All Systems

#=========================
# Get List of Computers
#=========================

$MyComputers=Get-ADComputer -filter * -Properties * | Where{($_.Enabled -eq $True) -and ($_.Operatingsystem -like "Windows*")} | Select -ExpandProperty Name
#====================
# Instantiate Array
#====================

$MyArray=@()
$MyFails=@()

#===================================
# Check Access to Each Computer
#===================================

Foreach($Comp in $MyComputers){
If((Invoke-Command -ErrorAction SilentlyContinue –ComputerName $comp –ScriptBlock {1}) –eq 1){
$MyArray+=$Comp
}Else{
$MyFails+=$Comp
}
}

#====================================================
# Export Pass failed for Further Review
#====================================================

$MyArray | Out-File C:\temp\PassedDNSSystems.txt
$MyFails | Out-File C:\temp\FailedDNSSystems.txt

#===================================
# ---- Main Command to be Executed------ 

#===================================
$MyCommand={
$MyNS=Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object {($_.DNSServerSearchOrder -ne $null)} | Select -ExpandProperty DNSServerSearchOrder

#===================================
# Pull DNS Settings add to Object
#===================================

$Obj=New-Object PSObject
$Obj |Add-Member NoteProperty ServerName ($env:COMPUTERNAME)
$Obj |Add-Member NoteProperty DNS_Settings ($MyNS)
Return $Obj
}
#End Main Command
#===============================================
# ------ Execution & Export to File ------------
#===============================================

$MyReturnValues=Invoke-Command $MyArray -ScriptBlock $MyCommand
$MyReturnValues | Select ServerName, DNS_Settings | Export-Csv C:\temp\DNS.csv -NoTypeInformation -Append