question

NicholasJConger-8728 avatar image
0 Votes"
NicholasJConger-8728 asked RichMatheisen-8856 answered

Add-DhcpServerV4Scope import-csv LeaseDuration Time Value Entry

Hello,

We're trying to export about 450 scopes and re-create them on another DHCP Server importing the values from a CSV and running the Add-DhcpServerV4Scope cmdlet.

Everything works perfectly except the LeaseDuration value.

See the value is set to "day.hrs:mins:secs" format.

Running the script gets the error "Add-DhcpServerv4Scope : Cannot process argument transformation on parameter 'LeaseDuration'. Cannot convert null to type "System.TimeSpan"."

Does anybody have a value that the time can be inputted into a CSV that the Add-DhcpServerV4Scope cmdlet can use to set the scope value to the specified LeaseDuration.

windows-server-powershellwindows-dhcp-dns
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered

Hello,

I am not sure how exactly looks like the csv that you are having prepared, but to import multiple DHCP scopes to a DHCP server. Some settings needs to be added on top level. For example DNS servers.

Required header in CSV:
name;description;startrange;endrange;subnetmask;scopeid;router

$dhcpserver = "1.1.1.1"
$scopes = Import-Csv -Path dhcp.csv -Delimiter ";"
foreach ($scope in $scopes)
{
$name = $scope.name
$description = $scope.description
Write-Output "Creating scope $name"
Add-DhcpServerv4Scope -ComputerName $dhcpserver -Name "$name" -Description "$description" -StartRange $scope.startrange -EndRange $scope.endrange -SubnetMask $scope.subnetmask -State Active -LeaseDuration 1.00:00:00
Set-DhcpServerv4OptionValue -Router $scope.router -ScopeId $scope.scopeid -ComputerName $dhcpserver
}



--If the reply is helpful, please Upvote and Accept as answer--

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

Is it safe to assume that you're using a variable as the value for the lease duration? The error says that the variable either doesn't exist or that it contains a $null value.

If you can't find where the problem lies, try adding Set-PSDebug -Strict at the the beginning of your script. If you try to use an undeclared variable you'll get an error like "The variable '$NewVar' cannot be retrieved because it has not been set." along with the line number in the script.

It may simply be a misspelling of the variable name (or a property name).

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.