# CSV dosya yolunu belirtin
$csvPath = “C:\path\to\contacts.csv”
# CSV dosyasını oku
$contacts = Import-Csv -Path $csvPath
# Grubun adını belirtin
$distributionGroupName = “acenteler”
# Log dosyası oluşturma
$logFile = “C:\path\to\contact_creation_log.txt”
New-Item -Path $logFile -ItemType File -Force | Out-Null
# Her bir satır için yeni bir kontak oluştur, adres defterinden gizle ve mail grubuna ekle
foreach ($contact in $contacts) {
# Önce kontağın var olup olmadığını kontrol et
$existingContact = Get-MailContact -Identity $contact.Alias -ErrorAction SilentlyContinue
if ($existingContact -eq $null) {
try {
# Yeni MailContact oluştur
$newContact = New-MailContact -DisplayName $contact.DisplayName -Name $contact.Name -Alias $contact.Alias -ExternalEmailAddress $contact.EmailAddress -OrganizationalUnit $contact.OrganizationalUnit -ErrorAction Stop
# Kontağı adres defterinden gizle
Set-MailContact -Identity $newContact.Identity -HiddenFromAddressListsEnabled $true
# Kontağı mail grubuna ekle
Add-DistributionGroupMember -Identity $distributionGroupName -Member $newContact.Alias
# Başarılı ekleme mesajı
$successMessage = “Successfully created and added contact: $($contact.Alias)”
Write-Host $successMessage
Add-Content -Path $logFile -Value $successMessage
}
catch {
$errorMessage = “Error for contact $($contact.Alias): $($_.Exception.Message)”
Write-Host $errorMessage
Add-Content -Path $logFile -Value $errorMessage
}
} else {
$skipMessage = “Contact $($contact.Alias) already exists. Skipping…”
Write-Host $skipMessage
Add-Content -Path $logFile -Value $skipMessage
}
}