Delete a SMTP address of a Public Folder – Powershell Script

1 Jan

In this script we remove a given secondary SMTP-Proxyaddress of mail-enabled Public Folders in Exchange 2003.

The architecture is as:

  1. Look for all obejcts in OU Microsoft Exchange System Objects
  2. Exclude certain objects from beeing modified
  3. Traverse all addresses of each object found
  4. if you find a address by type “smtp:” and a certain domain
    remove this entry form the proxy addresslist



Download Script code here: RemoveProxyAddressFromPublicFolder.txt 


 


code snippet:


$ProxyAddressToRemove = “bgetem.de$”

$Logfile=“c:\removePublicFolder.log”

“Start” | out-file -filepath $Logfile -encoding default -Append

$object=get-QADObject -SearchRoot ‘root.domain/Microsoft Exchange System Objects’

$anzahl=$object.Count

“$anzahl Objekte in der OU Microsoft Exchange System Objects gefunden” | out-file -filepath $Logfile -encoding default -append

for ($memberCount=0; $memberCount -le $anzahl1; $memberCount++)

{

$PublicFolderName=$object[$memberCount]

“$PublicFolderName wurde gefunden” | out-file -filepath $Logfile -encoding default -append

switch -wildcard ($PublicFolderName.name)

{

‘Default*’ {“$PublicFolderName wird laut Regeln nicht bearbeitet” | out-file -filepath $Logfile -encoding default -append}

‘internal*’ {“$PublicFolderName wird laut Regeln nicht bearbeitet” | out-file -filepath $Logfile -encoding default -append}

‘Schedule+ Free Busy*’ {“$PublicFolderName wird laut Regeln nicht bearbeitet” | out-file -filepath $Logfile -encoding default -append}

‘Offline Address Book*’ {“$PublicFolderName wird laut Regeln nicht bearbeitet” | out-file -filepath $Logfile -encoding default -append}

‘schema-root*’ {“$PublicFolderName wird laut Regeln nicht bearbeitet” | out-file -filepath $Logfile -encoding default -append}

‘globalevents*’ {“$PublicFolderName wird laut Regeln nicht bearbeitet” | out-file -filepath $Logfile -encoding default -append}

‘exchangeV1*’ {“$PublicFolderName wird laut Regeln nicht bearbeitet” | out-file -filepath $Logfile -encoding default -append}

‘microsoft*’ {“$PublicFolderName wird laut Regeln nicht bearbeitet” | out-file -filepath $Logfile -encoding default -append}

‘OWAScratchPad*’ {“$PublicFolderName wird laut Regeln nicht bearbeitet” | out-file -filepath $Logfile -encoding default -append}

‘SystemMailbox*’ {“$PublicFolderName wird laut Regeln nicht bearbeitet” | out-file -filepath $Logfile -encoding default -append}

‘Exchange Install*’ {“$PublicFolderName wird laut Regeln nicht bearbeitet” | out-file -filepath $Logfile -encoding default -append}

‘StoreEvents*’ {“$PublicFolderName wird laut Regeln nicht bearbeitet” | out-file -filepath $Logfile -encoding default -append}

default

{

$PublicFolder=[ADSI]“LDAP://$PublicFolderName”

$PublicFolderEmail=$PublicFolder.proxyAddresses

{“$PublicFolderName mit Pfad: $PublicFolder und Adressen: $PublicFolderEmail wird laut Regeln bearbeitet” | out-file -filepath $Logfile -encoding default -append}

for ($adrCount=0; $adrCount -le $PublicFolderEmail.count1 ;$adrCount++)

{

$fulladdress=$PublicFolderEmail[$adrCount]

$typ=$fulladdress.substring(0,5)

$address=$fulladdress.substring(5)

if($typ -ceq “smtp:” -and $address -match $ProxyAddressToRemove)

{

$PublicFolder.proxyAddresses.Remove(“$fulladdress”)

“Adresse: $fulladdress wurde gelöscht” | out-file -filepath $Logfile -encoding default -append

if ($PublicFolder -ne $null){$PublicFolder.setinfo()}

}

}

}

}

}

“Ende” | out-file -filepath $Logfile -encoding default -Append

Leave a Reply

Your email address will not be published. Required fields are marked *