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
Technology Tips and News
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
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
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.
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
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
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/
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?
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
I still get this:
PS C:\temp> get-tmdhcpdns1 -computername dhcp01sjrunning Get-Command Get-TMDhcpDNS fails.
PS C:\temp> Get-Command Get-TMDhcpDNSWhen you dot sourced the script, did you include the first dot?
. .\Get-TMDhcpDNS1.0.1.ps1If 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
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
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
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!!!
When you dot sourced the script, did you include the first dot?
. .\Get-TMDhcpDNS1.0.1.ps1If 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
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