# Importer le module Active Directory Import-Module ActiveDirectory $varCheminRepertoireScript = [System.IO.Path]::GetDirectoryName($MyInvocation.MyCommand.Definition) $currentScriptName = $MyInvocation.MyCommand.Name #Récupération du nom du script en cours $currentScriptName = $currentScriptName.substring(0,$($currentScriptName.lastindexofany("."))) $EmplacementFichier = "$varCheminRepertoireScript\$($currentScriptName).csv" # Spécifier les détails de l'enregistrement DNS à ajouter $dnsServer = "172.16.8.8" $ListVMs = Import-Csv -Path $EmplacementFichier -Delimiter "`t" foreach ($UneVM in $ListVMs) { $recordName = $UneVM.recordName if ($recordName) { $zoneName = $UneVM.Zone Write-Host $recordName if ($($UneVM.Type)){ if ($($UneVM.Type) -ieq "Cname"){ $canonicalName = $UneVM.Alias Add-DnsServerResourceRecord -ZoneName $zoneName -CName -Name $recordName -HostNameAlias $canonicalName -ComputerName $dnsServer } if ($($UneVM.Type) -ieq "A"){ $recordType = "A" # Type d'enregistrement (A pour un enregistrement de type Adresse IP) $recordName = $UneVM.recordName $recordValue = $UneVM.Alias Add-DnsServerResourceRecord -ZoneName $zoneName -A -Name $recordName -IPv4Address $recordValue -ComputerName $dnsServer } } } }