winserver 2019 根据表格自动导入dhcp 作用域

一、必要条件

        1.winserver 2019

        2.通外网,需要下载模版

        3.一个名称叫dhcp_ip_list.xlsx的文件

                1.附件为例子,修改其中的数据即可

        4.默认租期为8小时

二、代码

Install-Module -Name ImportExcel

# Read the xlsx file
$data = Import-Excel -Path "./dhcp_ip_list.xlsx"


$leaseDuration = New-TimeSpan -Hours 8


# Iterate through each row
$data | ForEach-Object {
    $row = $_

    # Get the column values
    $scope_name = $row."scope_name"
    $start_ip = $row."start_ip"
    $end_ip = $row."end_ip"
    $mask = $row."mask"
    $exclude_start_ip = $row."exclude_start_ip"
    $exclude_end_ip = $row."exclude_end_ip"
    $router = $row."router"
    $scope_id = $row."scope_id"
    $dns1 = $row."dns1"
    $dns2 = $row."dns2"
    $dns3 = $row."dns3"

    # Create a new DHCP scope
    Add-DhcpServerv4Scope -Name $scope_name -StartRange $start_ip -EndRange $end_ip -SubnetMask $mask  -LeaseDuration $leaseDuration  -State Active
    # Set the router and DNS server
    Set-DhcpServerv4OptionValue -ScopeId $scope_id -DnsServer $dns1,$dns2,$dns3 -Router $router 
    # Exclude the IP range
    Add-DhcpServerv4ExclusionRange -ScopeId $scope_id -StartRange $exclude_start_ip -EndRange $exclude_end_ip
    
}




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值