WINDOWS SYSTEM ADMIN BOOK
search
⌘Ctrlk
WINDOWS SYSTEM ADMIN BOOK
  • ▶️INTRO
  • microchipHardware/Physical Machines
  • galaxySystem Configuration
  • windowsWindows Server
  • linuxLinux Servers
  • dockerContainers
  • line-columnsControl Panels
  • head-side-gogglesVirtualization
  • serverWeb Servers and WAFs
  • shield-crossVPNs and Proxy Servers
  • databaseDatabase Servers
  • keycdnCDN Servers
  • internet-explorerWeb Dev Stacks
  • ticketsIT Ticketing Systems
  • awsAWS Environment
  • microsoftAzure Environment
  • bootBackup and Security
  • envelopeEmail and Office 365
    • circle-exclamationTroubleshooting
    • robotAutomation
      • rectangle-terminalPowershell Commands
      • chart-simpleMS-Graph Commands
      • user-magnifying-glassMS-Graph: Manage Users and Groups
      • windowsPowershell: Deleting Users in Microsoft 365
      • windowsPowershell: Recovering Deleted Users in Microsoft 365
      • folder-arrow-upEnable Archive Policy & Assign Retention Tag for a User in Microsoft 365
      • user-magnifying-glassList all allias in m365 with a for a specific username
      • questionDelete all the guest users from m365 tenant
      • envelope-open-dollarHow to Enable “Send From Alias” in Microsoft 365 (Exchange Online)
      • folder-userCreate Bulk Contacts
      • file-arrow-downHow to Move Mailbox Items to Archive Using Managed Folder Assistant (Exchange Online)
    • phabricatorHybrid Mail Setup
    • fingerprintEmail Authentication
    • envelope-dotMail Clients
    • microsoftOffice 365
    • gGoogle Workspace
    • envelopeMailEnable
    • envelope-openSmarterMail
    • windowsMicrosoft Teams
    • microsoftMicrosoft Defender for Office 365
    • ballot-checkMicrosoft Purview
    • id-badgeMicrosoft Entra ID
    • envelope-openExchange Admin
    • up-from-bracketSharepoint
    • zZoho Mail
  • block-brick-fireFirewalls and Access Points
  • ethernetNetworking
  • location-arrowMigration
  • alienMonitoring
  • hospitalData Center
  • list-checkLoad Balancers
  • microchipOther Technologies
  • seal-exclamationCertifications
  • ⏸️OUTRO
gitbookPowered by GitBook
block-quoteOn this pagechevron-down
  1. envelopeEmail and Office 365chevron-right
  2. robotAutomation

folder-userCreate Bulk Contacts

hashtag
PowerShell Script

PreviousHow to Enable “Send From Alias” in Microsoft 365 (Exchange Online)chevron-leftNextHow to Move Mailbox Items to Archive Using Managed Folder Assistant (Exchange Online)chevron-right

Last updated 1 month ago

# ===============================
# CONFIGURATION
# ===============================
 
$CsvPath = "C:\Users\test\Desktop\bulk_contacts\Import_Contact_Template.csv"
$LogFile = "C:\Users\test\Desktop\log.txt"
 
# ===============================
# CONNECT TO EXCHANGE ONLINE
# ===============================
 
Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline
 
# ===============================
# IMPORT CONTACTS
# ===============================
 
$Contacts = Import-Csv -Path $CsvPath
 
foreach ($Contact in $Contacts) {
 
    try {
 
        # Check if contact already exists
        $ExistingContact = Get-MailContact -Filter "ExternalEmailAddress -eq '$($Contact.Email)'" -ErrorAction SilentlyContinue
 
        if ($ExistingContact) {
            Write-Host "Already exists: $($Contact.DisplayName)" -ForegroundColor Yellow
            Add-Content -Path $LogFile -Value "$(Get-Date) - Skipped (Exists): $($Contact.DisplayName)"
            continue
        }
 
        # Create Mail Contact
        New-MailContact `
            -Name $Contact.DisplayName `
            -DisplayName $Contact.DisplayName `
            -ExternalEmailAddress $Contact.Email
 
        Write-Host "Created: $($Contact.DisplayName)" -ForegroundColor Green
        Add-Content -Path $LogFile -Value "$(Get-Date) - Created: $($Contact.DisplayName)"
 
    }
    catch {
        Write-Host "Error creating $($Contact.DisplayName): $_" -ForegroundColor Red
        Add-Content -Path $LogFile -Value "$(Get-Date) - ERROR: $($Contact.DisplayName) - $_"
    }
}
 
# ===============================
# DISCONNECT
# ===============================
 
Disconnect-ExchangeOnline -Confirm:$false
Write-Host "Import completed."