PowerSchell : Création en masse de scope DHCP

Un petit script écrit rapidement pour automatiser la création de scope sur un serveur de lab. Le script permet de configurer les options 3, 6, 15, 66 et 67 en customisant les valeurs selon le besoin. A adapter selon vos besoins !

$ScopeDesc    = @('Lab 130','Lab 131','Lab 132','Lab 133','Lab 134','Lab 135','Lab 136','Lab 137','Lab 138','Lab 139','Lab 140')
$ScopeIPStart = @('172.16.130.1','172.16.131.1','172.16.132.1','172.16.133.1','172.16.134.1','172.16.135.1','172.16.136.1','172.16.137.1','172.16.138.1','172.16.139.1','172.16.140.1')
$ScopeIPStop  = @('172.16.130.252','172.16.131.252','172.16.132.252','172.16.133.252','172.16.134.252','172.16.135.252','172.16.136.252','172.16.137.252','172.16.138.252','172.16.139.252','172.16.140.252')

For ($i=0; $i-le ($ScopeDesc.count -1);$i++)
{
    Write-Host "Creating Scope " ($ScopeIPStop[$i] -replace '.252','.0') "..." -NoNewline
    
    $trash = Add-DhcpServerv4Scope -StartRange $ScopeIPStart[$i] -EndRange $ScopeIPStop[$i] -Name $ScopeDesc[$i] -Description $ScopeDesc[$i] -State Active -LeaseDuration 0.23:00:00 -SubnetMask 255.255.255.0 -Type Both
    $trash = Set-DhcpServerv4OptionValue -ScopeId ($ScopeIPStop[$i] -replace '.252','.0') -DnsDomain (($ScopeDesc[$i] -replace ' ','') + ".ms-sec.fr") 
    $trash = Set-DhcpServerv4OptionValue -ScopeId ($ScopeIPStop[$i] -replace '.252','.0') -DnsServer $ScopeIPStart[$i] -Force 
    $trash = Set-DhcpServerv4OptionValue -ScopeId ($ScopeIPStop[$i] -replace '.252','.0') -Router ($ScopeIPStop[$i] -replace '.252','.254') 
    $trash = Set-DhcpServerv4OptionValue -ScopeId ($ScopeIPStop[$i] -replace '.252','.0')  -OptionId 66 -Value ($ScopeIPStop[$i] -replace '.252','.253')
    $trash = Set-DhcpServerv4OptionValue -ScopeId ($ScopeIPStop[$i] -replace '.252','.0')  -OptionId 67 -Value "Boot\x64\wdsmgfw.efi" 

    Write-host "done." -ForegroundColor Yellow
}

Lien Permanent pour cet article : https://ms-sec.fr/?p=2740