Hello!
This script is supposed to first tell the user if the free IPs of each scope is more or lease than the input number. Then its supposed to ask the user what scope and to which mac address the lease should reserve to. Even tho the script should work as intended the reservation does not exist in my DHCP.
Write-Host 'Enter a number of addresses'
$Input = Read-Host
$inputInt = [int]$Input
foreach($scope in Get-DhcpServerv4ScopeStatistics)
{
if($scope.Free -gt $Input){
Write-Host "Scope $($scope.ScopeID) has more than $inputInt free ips"
}
elseif($scopeFree -lt $inputInt){
Write-Host 'scope' $($scope.ScopeID) 'has less than' $inputint 'free ips'
}
}
Write-Host 'Do you want to make an ip reservation? [Y/n]'
$input2 = Read-Host
if($input2 -eq 'Y'){
Write-Host 'Enter the scope you wnat to use'
$inputScope = Read-Host
Write-Host 'Enter a MAC-address'
$inputMac = Read-Host
$freeIP = Get-DhcpServerv4FreeIPAddress -ScopeId $inputScope -NumAddress 1
Write-Host 'A reservation is going to be made for ' $freeIP 'using scope' $inputScope 'and MAC adress' $inputMac -FO Yellow
Write-Host 'Do you Want to make this reservation? [Y/n]'
$input3 = Read-Host
if($input3 -eq 'Y'){
Add-DhcpServerv4Reservation -ScopeId $inputScope -IPAddress $freeIP -ClientId $InputMac
Write-Host 'DHCP Reservation has been made' -FO Yellow
}
else{
break
}
}
else{
break
}
Read-Host -Prompt "Press Enter to exit"
Thanks in advance!