script to export all DHCP scopes with DNS settings into excel file

Hello,
I am looking for a script to export all DHCP scopes with DNS settings on each scope into excel file.

Thank you very much!
creative555Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Thomas GrassiSystems AdministratorCommented:
0
LearnctxEngineerCommented:
Seeing as you're using server 2012 you have the DHCP cmdlets available to you.

$DHCPServer = "DHCP Server Name"
$Scopes = Get-DhcpServerv4Scope -ComputerName $DHCPServer

$ArrData = New-Object System.Collections.ArrayList

Foreach ($Scope in $Scopes)
{
	$Priority = 0
	try
	{
		$DNSSettings = Get-DhcpServerv4OptionValue -ComputerName $DHCPServer -ScopeId $Scope.ScopeID.IPAddresstostring -OptionId 6 -ErrorAction Stop
		Foreach ($DNSServer in $DNSSettings.Value)
		{
			$Priority++
			$ObjData = "" | Select Server, Scope, DNS, Priority
			$ObjData.Server = $DHCPServer
		        $ObjData.Scope = $Scope.ScopeID.IPAddresstostring
			$ObjData.DNS = $DNSServer
			$ObjData.Priority = $Priority
			[void]$ArrData.Add($ObjData)
		}
	}
	catch
	{
		$ObjData = "" | Select Server, Scope, DNS, Priority
		$ObjData.Server = $DHCPServer
		$ObjData.Scope = $Scope.ScopeID.IPAddresstostring
		[void]$ArrData.Add($ObjData)
	}
}

$ArrData | Export-CSV -NoType C:\Export.csv

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
creative555Author Commented:
Hello,
When you export DHCP scopes, it will not stop the DHCP service during that time?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2012

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.