如何使用csv自动添加和删除dhcp预留



我的client.csv格式为:

ScopeId,Name,ClientId,Ipaddress
10.10.10.0,Computer1,1a-1b-1c-1d-1e-1f,10.10.10.10
10.10.10.0,Computer2,2a-2b-2c-2d-2e-2f,10.10.10.11
10.10.10.0,Computer3,3a-3b-3c-3d-3e-3f,10.10.10.12

我的client.csv格式(当用户的ClientID为空时(:

ScopeId,Name,ClientId,Ipaddress
10.10.10.0,Computer1,1a-1b-1c-1d-1e-1f,10.10.10.10
10.10.10.0,Computer2,2a-2b-2c-2d-2e-2f,10.10.10.11
10.10.10.0,Computer3,,10.10.10.12

当我用csv运行powershell时,自动添加dhcp服务器预订成功。但是,当用户的ClientID为null时,PowerShell无法自动删除dhcp服务器保留。我的PowerShell脚本有问题吗?

$ComputerName="WIN-OO4RE715BV8.test.com"
if (!$args) { 
Write-Host "client.csv"
} 
ELSE
{
$dhcpdata=Import-CSV $args
foreach ($dhcp in $dhcpdata){ 
$ScopeId=$dhcp.ScopeId
$Name=$dhcp.Name
$ClientId=$dhcp.ClientId
$IPAddress=$dhcp.IPAddress
if ($ClientId -eq $null) {
Remove-DhcpServerv4Reservation -ScopeId $ScopeId -Name $Name -ClientId $ClientId -IPAddress $IPAddress 
}
Add-DhcpServerv4Reservation -ScopeId $ScopeId -Name $Name -ClientId $ClientId -IPAddress $IPAddress    
} 
} 
$ComputerName="WIN-JA5I029SJFM.test.com"
if (!$args) { 
Write-Host "client.csv"
} 
ELSE
{
$dhcpdata=Import-CSV $args
foreach ($dhcp in $dhcpdata){ 
$ScopeId=$dhcp.ScopeId
$Name=$dhcp.Name
$ClientId=$dhcp.ClientId
$IPAddress=$dhcp.IPAddress
Add-DhcpServerv4Reservation -ScopeId $ScopeId -Name $Name -ClientId $ClientId -
IPAddress $IPAddress
if(!$ClientId)
{
echo Remove-DhcpServerv4Reservation -ComputerName "$ComputerName" -IPAddress $IPAddress
Remove-DhcpServerv4Reservation -ComputerName "$ComputerName" -IPAddress $IPAddress
}
}
}

相关内容

  • 没有找到相关文章

最新更新