Archive for the ‘ADSI’ tag
Disconnected Mailboxes in Exchange 2003
I was looking into finding all disconnected/orphaned mailboxes in an Exchange2003 org. Normally I would use either an old VBScript I have or the Exchange 2003 ESM. I thought it would be good to experiment with PowerShell and try to simplify the VBScript that I have.
Below is a PowerShell script that utilizes ADSI to gather all Exchange 2003 servers in your configuration container. Then for each server it utilizes WMI to connect to the Root/MicrosoftExchangeV2 ‘NameSpace’ and the Exchange_Mailbox provider. From there we filter on only mailboxes that the “DateDiscoveredAbscentInDS” property is NOT NULL. That data is then passed through the pipeline to a Select-Object where a custom Hash table is built to display the Server Name of the filtered mailboxes. The filtered mailboxes and the selected data is then passed through the pipeline and exported to a .csv file on the root of C:\ named with the format C:\DisconnectedMailboxes_%Servername%.csv.
Code:
[String]$StrFilter = "(objectCategory=msExchExchangeServer)" $objRootDSE = [ADSI]"LDAP://RootDSE" [String]$strContainer = $objRootDSE.configurationNamingContext $objSearcher = New-Object System.DirectoryServices.DirectorySearcher $objSearcher.SearchRoot = New-object System.DirectoryServices.DirectoryEntry("LDAP://$strContainer") $objSearcher.PageSize = 1000 $objSearcher.Filter = $strFilter $objSearcher.SearchScope = "Subtree" $colResults = $objSearcher.FindAll() ForEach ($objResult in $colResults) { [String]$ServerDN = $objResult.Properties.distinguishedname $objServer = [ADSI]"LDAP://$ServerDN" [String]$Server = $objServer.cn Get-WmiObject -NameSpace Root\MicrosoftExchangeV2 -Class Exchange_Mailbox -Computer $Server | ` Where { $_.DateDiscoveredAbsentInDS -ne $null } | ` Select-Object @{N="Server";E={$_.__Server}},` StorageGroupName,StoreName,MailboxDisplayName,Size,DateDiscoveredAbsentInDS | ` Export-Csv "C:\DisconnectedMailboxes_$Server.csv" -NoTypeInformation }#End ForEach
Hope this helps.
All information is provided on an AS-IS basis, with no warranties and confers no rights.
Getting Proxy Addresses from an AD User Object
In Active Directory a user object can hold multiple “Proxy” addresses.
Using ADSI and LDAP the PowerShell script below enumerates all .proxyaddresses from a specific Active Directory user object.
This scripting technique can be used to get any Active Directory user object attributes.
All information is provided on an AS-IS basis, with no warranties and confers no rights.
Converting .diasplayName to .cn User object attributes
I routinely have to populate Active Directory Email distribution lists from lists of employee full names. These list usually contain the “.displayName” of the user. A quick way to resolve this is to convert the “.displayName” of the user into the users common name or “.cn” attribute and cut/paste them into the distribution lists “Members” box. I put the list of users display names into a C:\Scripts\Users.txt file and the script will produce a list of .cn attribute in the C:\Scripts\ConvertedUsers.txt file.
All information is provided on an AS-IS basis, with no warranties and confers no rights.
