Is there a way to extract a list of all user email addresses and alias email addresses from the security gateway?
Without having to open each individual user mailbox and call up the alias addresses individually.
The easiest way to do this is with a powershell script that uses the SGAPI module. Something like the following:
import-module sgapi
$URL = "http://127.0.0.1:4000/SecurityGateway.dll?view=xmlrpc"
$UserName = "admin@company.test" #Domain or Global Admin with access to the entire domain
$Password = "Password1"
$Domain = "Company.test"
Open-SGSession -URL $URL -UserName $UserName -Password $Password
ForEach($User in Get-SGUsers -Domain $Domain){
Write-Host "Mailbox: $($User.MailBox)"
$Aliases = Get-SGAliases -Email "$($User.MailBox)@$($User.Domain)"
Write-Host "Aliases:"
ForEach($Alias in $Aliases){
Write-Host $Alias.Address
}
}
Close-SGSession
You'll need to update the $URL, $UserName, $Password, and $Domain
This script just writes the list of mailbox and aliases to the screen, but you could update the script to store the data anywhere you'd like.
Thank you very much. The script works just as I need it to. Unfortunately, I'm not very familiar with Powershell programming, so could you modify the script for me so that the output is written to a file? That would be really nice. Thank you very much.
Free AI tools are usually pretty good at making these types of changes.
import-module sgapi
$URL = "http://127.0.0.1:4000/SecurityGateway.dll?view=xmlrpc"
$UserName = "admin@company.test" # Domain or Global Admin with access to the entire domain
$Password = "Password1"
$Domain = "Company.test"
# Define the path for the output file with a .csv extension
$OutputFilePath = "C:\Temp\MailboxAliases.csv"
# Ensure the directory exists if you use a specific path
# If the directory doesn't exist, the script might fail.
# Uncomment the following line if needed:
# New-Item -Path (Split-Path $OutputFilePath) -ItemType Directory -ErrorAction SilentlyContinue
# Initialize an empty array to hold our data objects
$ReportData = @()
Open-SGSession -URL $URL -UserName $UserName -Password $Password
Write-Host "Gathering mailbox and alias information..."
ForEach($User in Get-SGUsers -Domain $Domain){
$MailboxAddress = "$($User.MailBox)@$($User.Domain)"
Write-Host "Processing Mailbox: $MailboxAddress"
# Create a custom object for the primary mailbox itself
$MailboxObject = [PSCustomObject]@{
Mailbox = $MailboxAddress
Alias = $MailboxAddress # Primary address is its own alias
}
# Add to our array
$ReportData += $MailboxObject
$Aliases = Get-SGAliases -Email $MailboxAddress
ForEach($Alias in $Aliases){
# Create a custom object for each alias found
$AliasObject = [PSCustomObject]@{
Mailbox = $MailboxAddress
Alias = $Alias.Address
}
# Add to our array
$ReportData += $AliasObject
Write-Host " Found Alias: $($Alias.Address)"
}
}
Close-SGSession
# Export the collected objects to a CSV file
$ReportData | Export-Csv -Path $OutputFilePath -NoTypeInformation -Encoding UTF8
Write-Host "" # Blank line for readability
Write-Host "Script finished. Mailboxes and aliases have been saved to $OutputFilePath"