2020 | Scott W. Head  |  Sr. Systems Admin | Certified Microsoft Windows Server Administrator

PowerShell Managing Windows Servers

<#  
    .SYNOPSIS        
    Get DNS settings on remote machines 

    .DESCRIPTION
    ScriptsbyScott.com

    .NOTES 
    Requires Active Directory Module
    Requires Rights on Remote Machines   
    Author: Scott Head
    Min PSVer: Powershell 2.0
    Version: 1.0 (5/30/2019) Script Created             
#>

#======================
#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


$MyCommand={

   
    #==============================
    # Pull New DNS server Settings 
    #==============================

    $MyNewNS=@()
    $MyNewNS+=$env:COMPUTERNAME
    $MyNewNS+=Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object {($_.DNSServerSearchOrder -ne $null)} | Select -ExpandProperty DNSServerSearchOrder
    Return $MyNewNS

}


#===============================================
# -------------- Main Execution ----------------
#===============================================

Invoke-Command $MyArray -ScriptBlock $MyCommand | Out-File C:\temp\AllDNS.txt