PowerShell

Networking

Finding DHCP Servers


        $servers = Get-ADComputer -Filter {operatingsystem -like "*server*201*"}
        foreach($server in $servers){
                $svr = $server.Name
                if(test-wsman -computername $svr -ErrorAction SilentlyContinue){
                    
                    if( (Get-WindowsFeature -ComputerName $svr -Name dhcp -ErrorAction SilentlyContinue).installed -eq "True"){
                        Write-Output $svr
                    }
                }
        }

This will find all the servers (2012 and onwards). It checks that they are on and are responding to wsman requests.

Then it iterates through that list and finds the ones with DHCP installed and prints them to the screen.

Finding information about DHCP scopes on a DHCP Sever


        Invoke-Command { Get-DhcpServerv4scope |ft scopeid,name,leaseduration } -computername DHCP-SERVER01 
        

Setting the IP address and DNS server with PowerShell

        New-NetIPAddress -IPAddress 192.168.1.99 -DefaultGateway 192.168.1.1  -PrefixLength 24 -InterfaceAlias "ethernet" 
        Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses 192.168.1.2, 192.168.1.3

You may need to use Get-NetAdapter if the interface alias is not ethernet like on virtual servers or wi-fi.