# encoding: ascii
# api: powershell
# title: Object ProxyAddress Scan
# description: This script enables you too search AD for SMTP addresses that are possibly in use, using the QUEST PowerShell PSSnapIn and searching the “proxyAddress” attribute of objects. The output details either that the SMTP address is not found in AD or you get details of the object that owns the SMTP address.
# version: 0.1
# type: function
# author: Paul Brice
# license: CC0
# function: Get-ProxyAddresses
# x-poshcode-id: 1593
# x-archived: 2016-03-17T03:15:42
# x-published: 2010-01-20T08:07:00
#
# Save the code as: Get-ProxyAddress.ps1
# Usage: PS C:\> Get-ProxyAddress address@domain.com
#
Param (
[Parameter(Mandatory=$true,
Position=0,
ValueFromPipeline=$true,
HelpMessage="Enter SMTP address to search for in Active-Directory."
)]
[string]$objSMTP
)
Function Get-ProxyAddresses ([string]$Address){
$objAD = $null
$objAD = Get-QADObject -LdapFilter "(proxyAddresses=*$Address*)" -IncludeAllProperties -SizeLimit 0 -ErrorAction SilentlyContinue
Write-Output $objAD
}#Close Function
#Validate Quest PSSnapin is loaded
Add-PSSnapin -Name Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue
#Run Function to search AD for SMTP address
$Results = $null
$Results = Get-ProxyAddresses -Address $objSMTP | Select-Object Name,DisplayName,ObjectClass,Email,AccountisDisabled,AccountisLockedOut,MailNickName,LegacyExchangeDN -ErrorAction SilentlyContinue
IF($Results -eq $null){
Write-Host ""
Write-Host "No Object Found with .attribute[proxyAddress] containing $objSMTP."}
Else{$Results | Format-List *}
#End