none
How to dump the DNS options for each dhcp scope RRS feed

  • Question

  • 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

    Friday, April 24, 2015 6:23 PM

Answers

  • 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
    Tuesday, April 28, 2015 10:43 PM

All replies

  • 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. 
    Friday, April 24, 2015 6:40 PM
  • 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.





    Friday, April 24, 2015 7:12 PM
  • 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. 

    Friday, April 24, 2015 7:41 PM
  • 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/

    Tuesday, April 28, 2015 9:17 PM
  • 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?

    Tuesday, April 28, 2015 9:38 PM
  • 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

    Tuesday, April 28, 2015 9:47 PM
  • 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

    Tuesday, April 28, 2015 9:55 PM
  • 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.
    Tuesday, April 28, 2015 10:04 PM
  • 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

    Tuesday, April 28, 2015 10:19 PM
  • 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
    Tuesday, April 28, 2015 10:43 PM
  • 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 

    Tuesday, April 28, 2015 11:05 PM
  • Get-TMDhcpDNS -ComputerName dhcp01sj | Export-Csv -Path C:\DhcpDNSExport.csv -NoTypeInformation
    Tuesday, April 28, 2015 11:24 PM
  • 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 

    Tuesday, April 28, 2015 11:46 PM
  • There's ways to get around this problem. I'll work on it in the next day or so.
    Wednesday, April 29, 2015 12:45 AM
  • 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!!!

    Wednesday, April 29, 2015 12:47 AM
  • 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

    Wednesday, April 29, 2015 3:36 PM