Edit

Share via


Import-DhcpServer

Imports the Dynamic Host Configuration Protocol (DHCP) server service configuration, and optionally lease data, from a file.

Syntax

Default (Default)

Import-DhcpServer
    [-File] <String>
    [-BackupPath] <String>
    [-ScopeId <IPAddress[]>]
    [-Prefix <IPAddress[]>]
    [-ScopeOverwrite]
    [-Leases]
    [-ServerConfigOnly]
    [-Force]
    [-ComputerName <String>]
    [-CimSession <CimSession>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Description

The Import-DhcpServer cmdlet imports the Dynamic Host Configuration Protocol (DHCP) server service configuration, and optionally lease data, from the specified file.

If you specify either the ScopeId or the Prefix parameter, or both, only the specified scopes or prefixes are imported.

If you specify neither the ScopeId nor the Prefix parameter, all of the configurations that is contained in the file, and optionally any lease data, is imported.

If you specify the Leases parameter, the lease data in the specified file is imported in addition to configuration data.

If you specify the ScopeOverWrite parameter and the scope being imported exists on the destination server, the scope on the target DHCP server service is overwritten. If this parameter is not specified and the scope being imported exists on the destination DHCP server service, a warning message is displayed and the import proceeds to process the next scope being imported.

If you specify the ServerConfigOnly parameter, only the server level configuration is imported on the destination DHCP server service. If the file specified contains any scope information, the same information is not imported on the destination DHCP server service.

Examples

Example 1: Import configuration data

PS C:\> Import-DhcpServer -ComputerName "dhcpserver.contoso.com" -File "C:\exports\dhcpexport.xml" -BackupPath "C:\dhcpbackup\"

This example imports the configuration data in the specified file onto the DHCP server service that runs on the computer named dhcpserver.contoso.com. The file can contain DHCPv4 and DHCPv6 configuration data.

Example 2: Import configuration and lease data

PS C:\> Import-DhcpServer -ComputerName "dhcpserver.contoso.com" -File "C:\exports\dhcpexport.xml" -BackupPath "C:\dhcpbackup\" -Leases

This example imports the configuration and lease data in the specified file onto the DHCP server service that runs on the computer named dhcpserver.contoso.com. The file can contain DHCPv4 and DHCPv6 configuration data.

Example 3: Import configuration data for specified scopes

PS C:\> Import-DhcpServer -ComputerName "dhcpserver.contoso.com" -File "C:\exports\dhcpexport.xml" -BackupPath "C:\dhcpbackup\" -ScopeId 10.10.10.0,10.20.20.0

This example imports the configuration data for scopes 10.10.10.0 and 10.20.20.0 from the specified file onto the DHCP server service that runs on the computer named dhcpserver.contoso.com. If the export file contains scopes besides 10.10.10.0 and 10.20.20.0, those scopes are ignored. The DHCPv4 server level configuration data, if present in the export file, is also imported onto the DHCP server service.

Example 4: Import configuration and lease data for specified scopes

PS C:\> Import-DhcpServer -ComputerName dhcpserver.contoso.com -File "C:\exports\dhcpexport.xml" -BackupPath "C:\dhcpbackup\" -ScopeId 10.10.10.0,10.20.20.0 -Leases

This example imports the configuration and lease data for scopes 10.10.10.0 and 10.20.20.0 from the specified file onto the DHCP server service that runs on the computer named dhcpserver.contoso.com. If the export file contains scopes besides 10.10.10.0 and 10.20.20.0, those scopes are ignored. The DHCPv4 server level configuration data, if present in the export file, is also imported onto the DHCP server service.

Example 5: Import configuration and lease data for specified scopes with overwrite

PS C:\> Import-DhcpServer -ComputerName "dhcpserver.contoso.com" -File "C:\exports\dhcpexport.xml" -BackupPath "C:\dhcpbackup\" -ScopeId 10.10.10.0,10.20.20.0 -Leases -ScopeOverwrite

This example imports the configuration and lease data for scopes 10.10.10.0 and 10.20.20.0 from the specified file onto the DHCP server service that runs on the computer named dhcpserver.contoso.com. If the export file contains scopes besides 10.10.10.0 and 10.20.20.0, those scopes are ignored. The DHCPv4 server level configuration data, if present in the export file, is also imported onto the server. If the scopes 10.10.10.0 and 10.20.20.0 are already present on the DHCP server service that runs one the computer named dhcpserver.contoso.com, the scopes are deleted and recreated from the data in the export file.

Example 6: Import server level configuration data

PS C:\> Import-DhcpServer -ComputerName "dhcpserver.contoso.com" -File "C:\exports\dhcpexport.xml" -BackupPath "C:\dhcpbackup\" -ServerConfigOnly

This example imports only the server level configuration data in the specified file onto the DHCP server service that runs on the computer named dhcpserver.contoso.com. Any scope configuration data, if present in the file, is ignored.

Example 7: Import configuration data for specified scopes for DHCPv6

PS C:\> Import-DhcpServer -ComputerName "dhcpserver.contoso.com" -File "C:\exports\dhcpexport.xml" -BackupPath "C:\dhcpbackup\" -Prefix 2001:4898:7020:1020::,2001:4898:7020:1030::

This example imports the configuration data for scopes 2001:4898:7020:1020:: and 2001:4898:7020:1030:: from the specified file onto the DHCP server service that runs on the computer named dhcpserver.contoso.com. If the export file contains scopes besides 2001:4898:7020:1020:: and 2001:4898:7020:1030::, those scopes are ignored. The DHCPv6 server level configuration data, if present in the export file, is also imported onto the DHCP server service.

Example 8: Import configuration and lease data for specified scopes for DHCPv6

PS C:\> Import-DhcpServer -ComputerName "dhcpserver.contoso.com" -File "C:\exports\dhcpexport.xml" -BackupPath "C:\dhcpbackup\" -Prefix 2001:4898:7020:1020::,2001:4898:7020:1030:: -Leases

This example imports the configuration and lease data for scopes 2001:4898:7020:1020:: and 2001:4898:7020:1030:: from the specified file onto the DHCP server service that runs on the computer named dhcpserver.contoso.com. If the export file contains scopes besides 2001:4898:7020:1020:: and 2001:4898:7020:1030::, those scopes are ignored. The DHCPv6 server level configuration data, if present in the export file, is also imported onto the DHCP server service.

Example 9: Import configuration and lease data for specified scopes for DHCPv6 with overwrite

PS C:\> Import-DhcpServer -ComputerName "dhcpserver.contoso.com" -File "C:\exports\dhcpexport.xml" -BackupPath "C:\dhcpbackup\" -Prefix 2001:4898:7020:1020::,2001:4898:7020:1030:: -Leases -ScopeOverwrite

This example imports the configuration and lease data for scopes 2001:4898:7020:1020:: and 2001:4898:7020:1030:: from the specified file onto the DHCP server service that runs on the computer named dhcpserver.contoso.com. If the export file contains scopes besides 2001:4898:7020:1020:: and 2001:4898:7020:1030::, those scopes are ignored. The DHCPv6 server level configuration data, if present in the export file, is also imported onto the DHCP server service. If the scopes 2001:4898:7020:1020:: and 2001:4898:7020:1030:: are already present on the DHCP server service that runs on the computer named dhcpserver.contoso.com, the scopes are deleted and recreated from the data in the export file.

Example 10: Import scopes specified in a file

PS C:\> $ScopeIdList = Import-Csv -Path ".\ScopeList.txt"

PS C:\> Import-DhcpServer -ComputerName "dhcpserver.contoso.com" -File "C:\exportdir\dhcpexport.xml" -Leases -ScopeId $ScopeIdList.ScopeId -BackupPath "C:\dhcpbackup\"

This example imports a list of scopes specified in file named ScopeList.txt to the DHCP server service that runs on the computer named dhcpserver.contoso.com.

The Import-Csv cmdlet gets the list of scopes to import and returns it in the variable named $ScopeIdList. The second line imports the scopes using the variable named $ScopeIdList as input for the ScopeId parameter.

The file named ScopeList.txt should contain the following format:

ScopeID
10.10.10.0
10.20.20.0
10.30.30.0

Parameters

-BackupPath

Specifies the path where DHCP server database is backed up before it makes any configuration changes as part of the import operation.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:1
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-CimSession

Runs the cmdlet in a remote session or on a remote computer. Enter a computer name or a session object, such as the output of a New-CimSession or Get-CimSession cmdlet. The default is the current session on the local computer.

Parameter properties

Type:CimSession
Default value:None
Supports wildcards:False
DontShow:False
Aliases:Session

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-ComputerName

Specifies the DNS name, or IPv4 or IPv6 address, of the target computer that runs the DHCP server service.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False
Aliases:Cn

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Confirm

Prompts you for confirmation before running the cmdlet.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False
Aliases:cf

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-File

Specifies the name of the file from which the data is imported. If a complete file path is not specified, the file is read from the current working directory.

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Force

Forces the command to run without asking for user confirmation.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Leases

Specifies that the lease data is also imported.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Prefix

Specifies the subnet prefixes of IPv6 scopes which are imported.

Parameter properties

Type:

IPAddress[]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-ScopeId

Specifies the scope identifiers (IDs), in IPv4 address format, which must be imported.

Parameter properties

Type:

IPAddress[]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-ScopeOverwrite

Specifies that, if the scope being imported exists on the target server, the scope on the destination DHCP server service are overwritten.

If this parameter is not specified and the scope being imported exists on the destination DHCP server service, a warning message is displayed and import will proceed to process the next scope being imported.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-ServerConfigOnly

Specifies that only server level configuration is imported on the destination DHCP server service. If the file specified contains any scope information, the same is not imported on the destination DHCP server service.

Both DHCPv4 and DHCPv6 server level configurations is imported.

The server level configuration includes of (both v4 and v6):

  • Class definitions.
  • Option definitions.
  • Option values.
  • Server level Policies (DHCPv4).
  • MAC address filters (DHCPv4).
  • Other Server Properties (ConflictDetectionAttempts, DHCPv6 stateless store).

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Parameter properties

Type:SwitchParameter
Default value:None
Supports wildcards:False
DontShow:False
Aliases:wi

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Inputs

None

Outputs

None