Export DHCP Scope Options Values

Hi Readers,

Sharing a script that we have used to fullfil one of the requirement to extract the DNS scope option(006) values from all scopes on all dhcp servers.

First of all thx to the creator of DHCP powershell module writer.

My script is based on this module & it is included in the below download link

https://github.com/VikasSukhija/Downloads/blob/master/DHCP.zip

Just extract the script & run the batch file

we have used the value as 6 as we wanted to extract the DNS Scope option.

$idval = “6”  ### DNS Scope Option

Script will show the csv out pust as

################################################################## 
#              Author: Vikas SUkhija 
#              Description: Find DHCP SCope Options Values  
#              for particular scope option 
#              Date: 12/17/2014 
# 
# 
#################################################################### 
 
############Import Module & define variables################## 
 
Import-module .\Microsoft.DHCP.PowerShell.Admin.psm1 
 
$collection =@() 
$idval = "6"  ### DNS Scope Option 
 
$days = (get-date).adddays(-60) 
$date = get-date -format d 
$date = $date.ToString().Replace(“/”, “-”) 
$time = get-date -format t 
 
$time = $time.ToString().Replace(":""-") 
               $time = $time.ToString().Replace(" """$output = ".\" + "DHCPScopeOptions_" + $date + "_" + $time + "_.csv" 
 
 
########################################## 
$srv = Show-DHCPServers 
$servers$srv | select server 
$servers | foreach{  
$server = $_.server 
Write-host "Processing Server...............$server" -foregroundcolor Green 
$scope=Get-DHCPScope -server  $server 
#$scope 
$scp = $scope | Select Address 
#$scp 
 
    $scp | foreach{  
    $opt = Get-DHCPScope -server $server -scope $_.Address 
        $optscope = $opt | Select -expandproperty options | where{$_.optionId -like $idval| select Values  
 
$coll = “” | select ServerName,Scopename,Optionvalues 
 
$coll.ServerName = $server 
$coll.Scopename = $_.Address 
$coll.Optionvalues = $optscope.values 
 
 
$collection +$coll 
 
 
        } 
 
} 
 
$collection | select ServerName,Scopename,@{Name=”Optionvalues”;Expression={$_.Optionvalues}} | export-csv $output -notypeinfo 
 
####################################################################### 
 

Tech Wizard

https://techwizard.cloud

https://syscloudpro.com/

 

3 thoughts on “Export DHCP Scope Options Values

  1. I just want to execute this script on only one server (Locally), I have made some changes as per my need, but it is taking so much of time, please help me.

    $srv = hostname
    $server = hostname
    $servers= $srv | select server
    Write-host “Processing Server……………$server” -foregroundcolor Green
    $scope=Get-DHCPScope -server $server
    #$scope
    $scp = $scope | Select Address
    #$scp

    $scp | foreach{
    $opt = Get-DHCPScope -server $server -scope $_.Address
    $optscope = $opt | Select -expandproperty options | where{$_.optionId -like $idval} | select Values

    $coll = “” | select ServerName,Scopename,Optionvalues

    if($optscope.values -gt 0)
    {
    $coll.ServerName = $server
    $coll.Scopename = $_.Address
    $coll.Optionvalues = $optscope.values

    $collection += $coll
    }

    }

    $collection | select ServerName,Scopename,@{Name=”Optionvalues”;Expression={$_.Optionvalues}} | export-csv $output -notypeinfo

    In my scenario I have more then 1000 scopes and I want to export where option 162 is configured (Even it should export option 162 value also)

Leave a comment