rdefino
asked on
Need list of subnets from 2003 dhcp server
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
aa-denver: quick question, does it need to be running within the DHCP server?
ASKER
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.PowerShe ll.Admin.p sm1
$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.Nam e}},IPrang es
}
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
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.PowerShe
$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.Nam
}
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
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.
psm1 is considered as module.
and yes you don't need to do anything on the dhcp server at all.
ASKER
I still get this when running after changing the .ps1
PS E:\> .\dhcplist.ps1
Program 'Microsoft.DHCP.PowerShell .Admin.psm 1' 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.PowerShe ll.Admin.p sm1 <<<< .
At E:\dhcplist.ps1:1 char:14
+ $DHCPmodule = <<<< e:\Microsoft.DHCP.PowerShe ll.Admin.p sm1
+ 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 : ParameterArgumentValidatio nErrorNull NotAllowed ,M
icrosoft.PowerShell.Comman ds.ImportM oduleComma nd
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.Nam e}},IPrang es
+ CategoryInfo : ObjectNotFound: (Get-DHCPscope:String) [], Comma
ndNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS E:\> .\dhcplist.ps1
Program 'Microsoft.DHCP.PowerShell
n is associated with the specified file for this operation
At E:\dhcplist.ps1:1 char:54
+ $DHCPmodule = e:\Microsoft.DHCP.PowerShe
At E:\dhcplist.ps1:1 char:14
+ $DHCPmodule = <<<< e:\Microsoft.DHCP.PowerShe
+ 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 : ParameterArgumentValidatio
icrosoft.PowerShell.Comman
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.Nam
+ CategoryInfo : ObjectNotFound: (Get-DHCPscope:String) [], Comma
ndNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
place the ' in front and the back of the path.
$DHCPmodule = 'E:\Microsoft.DHCP.PowerSh ell.Admin. psm1'
$DHCPmodule = 'E:\Microsoft.DHCP.PowerSh
ASKER
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.PowerShe ll.Admin.p sm1:643 char:16
+ $work.Add <<<< ($optiondefs[$id].OptionNa me,$null)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Exception calling "Add" with "2" argument(s): "Item has already been added. Key
in dictionary: 'Avaya' Key being added: 'Avaya'"
At E:\Microsoft.DHCP.PowerShe
+ $work.Add <<<< ($optiondefs[$id].OptionNa
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
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
}
ASKER
I don't but I can download it. Would it be better?
It has been tested and working in version 3
And actually powershell 3 is a lot better than 2
And actually powershell 3 is a lot better than 2
Require .net 4.0 before install 3.0
ASKER
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.PowerShe ll.Admin.p sm1:643 char:7
+ $work.Add($optiondefs[$id] .OptionNam e,$null)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentException
Exception calling "Add" with "2" argument(s): "Item has already been added.
Key in dictionary: 'Avaya' Key being added: 'Avaya'"
At E:\Microsoft.DHCP.PowerShe
+ $work.Add($optiondefs[$id]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentException
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
I think you missed some code when you are copying it
ASKER
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.
Still the same error messages.
That's weird
Try to useFQDN on your dhcp server
Try to useFQDN on your dhcp server
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