Hey all,
To start, I am definitely newer to powershell and have been enjoying learning this so far. Unfortunately that has been a rough road since I only use it when I need to, but I’m trying to use it more and more frequently! I am attempting to scan an OU of computers for their DNS information. Then, based on that information, I want to change their DNS settings across the board. I started with this script:
$computers = Get-Content "C:\computers.txt" foreach ($computer in $computers){ Invoke-Command -ComputerName $computer -ScriptBlock { Get-DnsClientServerAddress -AddressFamily IPv4 -ErrorAction SilentlyContinue } -ErrorAction SilentlyContinue }
Some questions on what I would like to do:
- I saw somewhere else that instead of doing the Get-Content to get the information, that I can invoke Get-ADComputer from within this script. How would I do that?
- The Get-ADComputer cmdlet is what generated this text file, however there were a varying number of spaces after each of the computer names... anyway to ensure this is made without spaces so I don't have to manually manipulate this list?
- I need to be able to send computers the commands to update their DNS servers. We do NOT use DHCP, and instead preferred a Static Address setup for various reasons. When running Get-DnsClientServerAddress, there are a few things that may interfere with remotely providing each computer DNS information, which I need to work around that somehow, such as:
- Computers have different "InterfaceAlias" settings, such as Ethernet, Ethernet 2, etc. Most computers appear to have both, some may use Ethernet, some may use Ethernet 2.
- Each computer has a different Interface Index, so we wouldn't be able to solely search machines for that.
- All existing computers that do have DNS information all appear to have the same primary DNS server. Perhaps we could somehow filter for ONLY interface and machine names that have that specific server IP address set?
- Once we narrow that down, how would I either change or remove a secondary address if set? There are a few I want to change, and the majority do not have a secondary configured.