Solved

Need list of subnets from 2003 dhcp server

Posted on 2014-03-31
16
686 Views
Last Modified: 2014-04-21
I need to get a list of the subnets from a 2003 dhcp server. Not dump the scope, just an output of the subnets them shelves and nothing else.
0
Comment
Question by:rdefino
  • 9
  • 6
16 Comments
 
LVL 14

Accepted Solution

by:
Justin Yeung earned 235 total points
ID: 39966978
Download the DHCP module form microsoft
http://gallery.technet.microsoft.com/scriptcenter/05b1d766-25a6-45cd-a0f1-8741ff6c04ec

and save it as .psm1


$DHCPmodule = 'your path to the dhcp.psm1 file'
$DHCPServer = "name of the dhcp server"
Import-Module $DHCPmodule
$ScopeAddresses = Get-DHCPScope -Server $DHCPServer
foreach ($ScopeAddress in $ScopeAddresses)
{
Get-DHCPscope -Server $DHCPServer -Scope $ScopeAddress.Address| select-object @{N="Scope Name";E={$ScopeAddress.Name}},IPranges
}

Open in new window

0
 
LVL 4

Expert Comment

by:aa-denver
ID: 39966989
From command line, I believe this will do it.  You can redirect the output to a text file.

NETSH DHCP SERVER SCOPE DUMP

NETSH DHCP SERVER SCOPE DUMP > scopes.txt

Netsh is built in to all DHCP servers 2003 and newer.  You don't have to download anything.

Here is a complete reference.

http://technet.microsoft.com/en-us/library/cc787375(v=ws.10).aspx#BKMK_3
0
 
LVL 14

Expert Comment

by:Justin Yeung
ID: 39966993
aa-denver: quick question, does it need to be running within the DHCP server?
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:rdefino
ID: 39967053
I create the file Microsoft.DHCP.PowerShell.Admin.psm1, with the code from MS.

I put the files on my E:\, created and ran my new dhcplist.psm1 file in powershell, but on a workstation, not on the dhcp server itself.

Here is my file:

$DHCPmodule = e:\Microsoft.DHCP.PowerShell.Admin.psm1
$DHCPServer = "dhcp01sj"
Import-Module $DHCPmodule
$ScopeAddresses = Get-DHCPScope -Server $DHCPServer
foreach ($ScopeAddress in $ScopeAddresses)
{
Get-DHCPscope -Server $DHCPServer -Scope $ScopeAddress.Address| select-object @{N="Scope Name";E={$ScopeAddress.Name}},IPranges
}

And I get this error when running it:

Program 'dhcplist.psm1' failed to execute: No application is associated with the specified file for this operation
At line:1 char:16
+ .\dhcplist.psm1 <<<< .
At line:1 char:1
+  <<<< .\dhcplist.psm1
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedEx
   ception
    + FullyQualifiedErrorId : NativeCommandFailed
0
 
LVL 14

Expert Comment

by:Justin Yeung
ID: 39967068
the script should be named as dhcplist.ps1 not psm1

psm1 is considered as module.

and yes you don't need to do anything on the dhcp server at all.
0
 

Author Comment

by:rdefino
ID: 39967177
I still get this when running after changing the .ps1


PS E:\> .\dhcplist.ps1
Program 'Microsoft.DHCP.PowerShell.Admin.psm1' failed to execute: No applicatio
n is associated with the specified file for this operation
At E:\dhcplist.ps1:1 char:54
+ $DHCPmodule = e:\Microsoft.DHCP.PowerShell.Admin.psm1 <<<< .
At E:\dhcplist.ps1:1 char:14
+ $DHCPmodule = <<<<  e:\Microsoft.DHCP.PowerShell.Admin.psm1
    + CategoryInfo          : ResourceUnavailable: (:) [], ApplicationFailedEx
   ception
    + FullyQualifiedErrorId : NativeCommandFailed

Import-Module : Cannot bind argument to parameter 'Name' because it is null.
At E:\dhcplist.ps1:3 char:14
+ Import-Module <<<<  $DHCPmodule
    + CategoryInfo          : InvalidData: (:) [Import-Module], ParameterBindi
   ngValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,M
   icrosoft.PowerShell.Commands.ImportModuleCommand

The term 'Get-DHCPScope' is not recognized as the name of a cmdlet, function, s
cript file, or operable program. Check the spelling of the name, or if a path w
as included, verify that the path is correct and try again.
At E:\dhcplist.ps1:4 char:32
+ $ScopeAddresses = Get-DHCPScope <<<<  -Server $DHCPServer
    + CategoryInfo          : ObjectNotFound: (Get-DHCPScope:String) [], Comma
   ndNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

The term 'Get-DHCPscope' is not recognized as the name of a cmdlet, function, s
cript file, or operable program. Check the spelling of the name, or if a path w
as included, verify that the path is correct and try again.
At E:\dhcplist.ps1:7 char:14
+ Get-DHCPscope <<<<  -Server $DHCPServer -Scope $ScopeAddress.Address| select-
object @{N="Scope Name";E={$ScopeAddress.Name}},IPranges
    + CategoryInfo          : ObjectNotFound: (Get-DHCPscope:String) [], Comma
   ndNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
0
 
LVL 14

Expert Comment

by:Justin Yeung
ID: 39967209
place the ' in front and the back of the path.

$DHCPmodule = 'E:\Microsoft.DHCP.PowerShell.Admin.psm1'
0
 

Author Comment

by:rdefino
ID: 39967336
I see alot of these now. Also, where does this script output to? Can I get it dumped to a file?

Exception calling "Add" with "2" argument(s): "Item has already been added. Key
 in dictionary: 'Avaya'  Key being added: 'Avaya'"
At E:\Microsoft.DHCP.PowerShell.Admin.psm1:643 char:16
+       $work.Add <<<< ($optiondefs[$id].OptionName,$null)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException
0
 
LVL 14

Expert Comment

by:Justin Yeung
ID: 39967352
yes, by the way do you have powersehll 3.0?

$DHCPmodule = "E:\Microsoft.DHCP.PowerShell.Admin.psm1"
$DHCPServer = "dhcp01sj"
$Outpath = "your.csv"
Import-Module $DHCPmodule
$ScopeAddresses = Get-DHCPScope -Server $DHCPServer
foreach ($ScopeAddress in $ScopeAddresses)
{
Get-DHCPscope -Server $DHCPServer -Scope $ScopeAddress.Address| select-object @{N="Scope Name";E={$ScopeAddress.Name}},IPranges | export-csv $outpath -append
} 

Open in new window

0
 

Author Comment

by:rdefino
ID: 39967774
I don't but I can download it. Would it be better?
0
 
LVL 14

Expert Comment

by:Justin Yeung
ID: 39967787
It has been tested and working in version 3

And actually powershell 3 is a lot better than 2
0
 
LVL 14

Expert Comment

by:Justin Yeung
ID: 39967789
Require .net 4.0 before install 3.0
0
 

Author Comment

by:rdefino
ID: 39967821
I loaded 3.0 and ran it, but I still see these messages. should I worried about them?

Exception calling "Add" with "2" argument(s): "Item has already been added.
Key in dictionary: 'Avaya'  Key being added: 'Avaya'"
At E:\Microsoft.DHCP.PowerShell.Admin.psm1:643 char:7
+       $work.Add($optiondefs[$id].OptionName,$null)
+       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentException
0
 
LVL 14

Expert Comment

by:Justin Yeung
ID: 39967877
Try to go to the URL again and you should see copy code at the upper of the module

I think you missed some code when you are copying it
0
 

Author Comment

by:rdefino
ID: 39967885
I copied it again by clicking the copy code and pasted it into the psm1 files. Looks to all be thee, just like before.

Still the same error messages.
0
 
LVL 14

Expert Comment

by:Justin Yeung
ID: 39967890
That's weird

Try to useFQDN on your dhcp server
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn about cloud computing and its benefits for small business owners.
In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question