How to dump the DNS options for each dhcp scope

I have a 2012 dhcp server and need to get a dump to a csv file for each of the scopes 006 DNS option settings. How can I do this. 

Thanks

April 24th, 2015 2:26pm

Hi,

Here's a starting point:

https://technet.microsoft.com/en-us/library/jj590751.aspx

Free Windows Admin Tool Kit Click here and download it now
April 24th, 2015 2:41pm

I've been through that already and cannot find a way to get the dns entries. Was hoping someone here might have done it before. 
April 24th, 2015 2:43pm

You didn't try hard enough... ;). You need to use the Get-DhcpServerv4OptionValue cmdlet (or ...v6...).

Get-DhcpServerv4OptionValue -ComputerName <computername> | Where-Object OptionID -eq 6 | Select-Object Value

Edit: I think it's important that you know how I solved this problem. Perhaps you can put it to use yourself some time. The first thing I did was return all the 'get' DHCP cmdlets using this command: Get-Command -Module dhcp* -Name get-*. I quick scanned the cmdlets (actually, they're functions) and found the word 'option.' I jumped over to the DHCP MMC snap-in and quickly figured out why that sounded familiar. In the GUI, you right-click Server Options to get to this setting. I then ran the function in my example without piping it to the Where-Object cmdlet, and it return a value property. I then added the | Where-Object to filter down what was returned.

In writing this edit, I determined there's actually an -OptionID parameter, which means I could have better written my example. Here's that now:

Get-DhcpServerv4OptionValue -ComputerName <computername> -OptionID 6 | Select-Object Value

Always filter as close to the left as possible. That's means we don't want to pipe to something when we can filter with a built-in parameter.





Free Windows Admin Tool Kit Click here and download it now
April 24th, 2015 3:15pm

This I already did, but it only shows the dns setting for the Server options. I need the dns entry for each scope. Some scopes are not using the server dns option. 

April 24th, 2015 3:44pm

You didn't try hard enough... ;). You need to use the Get-DhcpServerv4OptionValue cmdlet (or ...v6...).

Get-DhcpServerv4OptionValue -ComputerName <computername> | Where-Object OptionID -eq 6 | Select-Object Value

Edit: I think it's important that you know how I solved this problem. Perhaps you can put it to use yourself some time. The first thing I did was return all the 'get' DHCP cmdlets using this command: Get-Command -Module dhcp* -Name get-*. I quick scanned the cmdlets (actually, they're functions) and found the word 'option.' I jumped over to the DHCP MMC snap-in and quickly figured out why that sounded familiar. In the GUI, you right-click Server Options to get to this setting. I then ran the function in my example without piping it to the Where-Object cmdlet, and it return a value property. I then added the | Where-Object to filter down what was returned.

In writing this edit, I determined there's actually an -OptionID parameter, which means I could have better written my example. Here's that now:

Get-DhcpServerv4OptionValue -ComputerName <computername> -OptionID 6 | Select-Object Value

Always filter as close to the left as possible. That's means we don't want to pipe to something when we can filter with a built-in parameter.





Free Windows Admin Tool Kit Click here and download it now
April 24th, 2015 7:12pm

You didn't try hard enough... ;). You need to use the Get-DhcpServerv4OptionValue cmdlet (or ...v6...).

Get-DhcpServerv4OptionValue -ComputerName <computername> | Where-Object OptionID -eq 6 | Select-Object Value

Edit: I think it's important that you know how I solved this problem. Perhaps you can put it to use yourself some time. The first thing I did was return all the 'get' DHCP cmdlets using this command: Get-Command -Module dhcp* -Name get-*. I quick scanned the cmdlets (actually, they're functions) and found the word 'option.' I jumped over to the DHCP MMC snap-in and quickly figured out why that sounded familiar. In the GUI, you right-click Server Options to get to this setting. I then ran the function in my example without piping it to the Where-Object cmdlet, and it return a value property. I then added the | Where-Object to filter down what was returned.

In writing this edit, I determined there's actually an -OptionID parameter, which means I could have better written my example. Here's that now:

Get-DhcpServerv4OptionValue -ComputerName <computername> -OptionID 6 | Select-Object Value

Always filter as close to the left as possible. That's means we don't want to pipe to something when we can filter with a built-in parameter.





April 24th, 2015 7:12pm

Thanks for the inspiration to write up a quick advanced function. This should get you your results.

Here's the Gallery link: https://gallery.technet.microsoft.com/Find-DNS-Servers-Being-640978d1
Here's my blog link: http://tommymaynard.com/script-sharing-find-dns-servers-being-used-by-dhcp-scopes-2015/

Free Windows Admin Tool Kit Click here and download it now
April 28th, 2015 5:18pm

Thanks!!!

But it's not running for me. Probably my mistake. I;m running it as:

.\Get-TMDhcpDNS1.0.1.ps1 -computername 'dhcpsj01'

Any idea what's wrong?

April 28th, 2015 5:39pm

It's written as a function, so you need to dot source the script to load the function into memory.

. .\Get-TMDhcpDNS1.0.1.ps1

Once the function is in memory, you can use as so:

Get-TMDhcpDNS -ComputerName dhcpsj01

Free Windows Admin Tool Kit Click here and download it now
April 28th, 2015 5:48pm

I still get this:

PS C:\temp> get-tmdhcpdns1 -computername dhcp01sj
get-tmdhcpdns1 : The term 'get-tmdhcpdns1' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:1
+ get-tmdhcpdns1 -computername dhcp01sj
+ ~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (get-tmdhcpdns1:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

April 28th, 2015 5:57pm

While the capitalization doesn't matter, the name of the function does. You have a 1 at the end of the function name in your example -- that's not going to work. Another step you can include, between the two I gave you above, is running Get-Command Get-TMDhcpDNS to ensure the function was added.
Free Windows Admin Tool Kit Click here and download it now
April 28th, 2015 6:06pm

running Get-Command Get-TMDhcpDNS  fails.  

PS C:\temp> Get-Command Get-TMDhcpDNS
Get-Command : The term 'Get-TMDhcpDNS' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Get-Command Get-TMDhcpDNS
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-TMDhcpDNS:String) [Get-Command], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand

April 28th, 2015 6:21pm

When you dot sourced the script, did you include the first dot?

. .\Get-TMDhcpDNS1.0.1.ps1
If dot sourcing still isn't working (for some mysterious reason), then open the .ps1 file in Notepad, press Ctrl+A to select everything, press Ctrl+C to copy the file's contents to your clipboard, then (without doing anything else in between), get back to your PowerShell console and right-click inside of it. When that's done, you may need to hit Enter a couple times to get back to your prompt. If either of these don't work, then there's not much else in which I can help. These are basic PowerShell fundamentals... Regardless of what option you do -- dot sourcing or copy/paste -- try running the function again: Get-TMDhcpDNS -ComputerName dhcpsj01
Edit: Typos


Free Windows Admin Tool Kit Click here and download it now
April 28th, 2015 6:44pm

Thank you. It's working now. 

One more question. When using format-table, the dns entries get truncated as :  

 {172.18.36.49, 172.1... Scope     

I was running the command to dump them to a csv file :

Get-TMDhcpDNS -ComputerName dhcp01sj | format-table > dhch01sj.csv

Is there a better way to get all of them to show?

thanks again 

April 28th, 2015 7:07pm

Get-TMDhcpDNS -ComputerName dhcp01sj | Export-Csv -Path C:\DhcpDNSExport.csv -NoTypeInformation
Free Windows Admin Tool Kit Click here and download it now
April 28th, 2015 7:25pm

That omitted the dns entries:

Name ScopeName ScopeID DNS ScopeOrServerDNS
dhcp01sj Datacenter 2400 10.24.0.0 System.Object[] Scope
dhcp01sj Datacenter 2480 10.24.8.0 System.Object[] Scope
dhcp01sj Datacenter 2800 10.28.0.0 System.Object[] Scope

I'm trying to figure it out, not a very good scripter. :)

thanks 

April 28th, 2015 7:47pm

There's ways to get around this problem. I'll work on it in the next day or so.
Free Windows Admin Tool Kit Click here and download it now
April 28th, 2015 8:47pm

I used this and it worked perfect.

Get-TMDhcpDNS -ComputerName dhcp01sj | format-table -autosize | Out-String -Width 4000 > c:dhcpdns.txt

Your script is awesome...thank you!!!

April 28th, 2015 8:49pm

When you dot sourced the script, did you include the first dot?

. .\Get-TMDhcpDNS1.0.1.ps1
If dot sourcing still isn't working (for some mysterious reason), then open the .ps1 file in Notepad, press Ctrl+A to select everything, press Ctrl+C to copy the file's contents to your clipboard, then (without doing anything else in between), get back to your PowerShell console and right-click inside of it. When that's done, you may need to hit Enter a couple times to get back to your prompt. If either of these don't work, then there's not much else in which I can help. These are basic PowerShell fundamentals... Regardless of what option you do -- dot sourcing or copy/paste -- try running the function again: Get-TMDhcpDNS -ComputerName dhcpsj01
Edit: Typos


  • Edited by tommymaynard Tuesday, April 28, 2015 10:52 PM
  • Marked as answer by rondefino Wednesday, April 29, 2015 12:35 AM
Free Windows Admin Tool Kit Click here and download it now
April 28th, 2015 10:43pm

Glad to hear that this worked for you -- you're very welcome.

I've updated the function to 1.0.2 and it now better handles the DNS servers when the function is piped to Export-Csv. Link: https://gallery.technet.microsoft.com/Find-DNS-Servers-Being-640978d1

April 29th, 2015 11:36am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics