Skip to content

Morlock52/PowerShell_FileApp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

PowerShell Distribution List Deletion Tool

This PowerShell script automates the deletion of distribution lists from Exchange Online or on-premises Exchange using a CSV file as input.

Features

  • CSV-based bulk deletion of distribution lists
  • Automatic column detection - supports Identity, EmailAddress, DisplayName, etc.
  • Comprehensive logging with timestamped log files
  • WhatIf mode for testing before actual deletion
  • Error handling with detailed error messages
  • Results export - creates a CSV report of all operations
  • Progress tracking with counters and status updates
  • Color-coded console output for easy monitoring

Prerequisites

For Exchange Online:

# Install the Exchange Online Management module
Install-Module -Name ExchangeOnlineManagement

# Connect to Exchange Online
Connect-ExchangeOnline -UserPrincipalName admin@yourdomain.com

For On-Premises Exchange:

# Add Exchange Management Shell snap-in
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn

CSV File Format

The CSV file should contain at least one of the following columns:

  • Identity (recommended)
  • EmailAddress
  • Email
  • PrimarySmtpAddress
  • DisplayName
  • Name

Example CSV:

Or with multiple columns:

Identity,DisplayName
[email protected],Sales Team
[email protected],Marketing Distribution List

Usage

Basic Usage

.\Delete-DistributionListsFromCSV.ps1 -CsvFilePath "C:\Lists\DistributionLists.csv"

Test Mode (WhatIf)

.\Delete-DistributionListsFromCSV.ps1 -CsvFilePath "C:\Lists\DistributionLists.csv" -WhatIf

Custom Log Path

.\Delete-DistributionListsFromCSV.ps1 -CsvFilePath "C:\Lists\DistributionLists.csv" -LogPath "C:\Logs\MyLog.log"

Output

The script generates two output files:

  1. Log File: DeleteDL_YYYYMMDD_HHMMSS.log

    • Contains detailed timestamped logs of all operations
    • Includes success, failure, and error messages
  2. Results CSV: DistributionLists_Results_YYYYMMDD_HHMMSS.csv

    • Contains a record of each distribution list processed
    • Includes status (Success/Failed/Skipped) and messages

Parameters

Parameter Required Description
CsvFilePath Yes Path to the CSV file containing distribution lists to delete
LogPath No Custom path for the log file (default: current directory with timestamp)
WhatIf No Test mode - shows what would be deleted without making changes

Example Workflow

  1. Export existing distribution lists (optional):

    Get-DistributionGroup | Select-Object Identity,DisplayName,PrimarySmtpAddress | Export-Csv -Path "AllDLs.csv" -NoTypeInformation
  2. Edit CSV to include only the distribution lists you want to delete

  3. Test with WhatIf:

    .\Delete-DistributionListsFromCSV.ps1 -CsvFilePath "AllDLs.csv" -WhatIf
  4. Execute deletion:

    .\Delete-DistributionListsFromCSV.ps1 -CsvFilePath "AllDLs.csv"
  5. Review results in the generated log and results CSV files

Error Handling

The script handles various scenarios:

  • Missing Exchange connection: Prompts to connect
  • Empty CSV: Validates file has content
  • Invalid identifiers: Logs and continues with next entry
  • Non-existent distribution lists: Logs error and continues
  • Throttling: Includes small delays between operations

Safety Features

  • WhatIf support: Test before executing
  • Confirmation bypass: Uses -Confirm:$false only in actual deletion
  • Detailed logging: Every action is logged
  • Results tracking: Creates comprehensive report of all operations

Troubleshooting

"No Exchange connection available"

  • Ensure you're connected to Exchange Online or on-premises Exchange
  • Run Connect-ExchangeOnline or add the Exchange snap-in

"Could not find a valid identifier column"

  • Check your CSV has one of the supported column names
  • Rename your column to Identity for best compatibility

"Access Denied" errors

  • Ensure your account has permissions to delete distribution lists
  • Typically requires "Organization Management" or "Recipient Management" role

Version History

  • v1.0 - Initial release with CSV-based bulk deletion functionality

License

MIT License - Free to use and modify

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors