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.

https://gallery.technet.microsoft.com/scriptcenter/05b1d766-25a6-45cd-a0f1-8741ff6c04ec

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

https://gallery.technet.microsoft.com/scriptcenter/Export-DHCP-Scope-Options-7ddbc906

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 
 
####################################################################### 
 

Regards

Sukhija Vikas

http://msexchange.me

Advertisements

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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s