I’ve looked everywhere I can to find an answer to this, but come up empty, so maybe someone can put me on track.<\/p>\n
I want to export a CSV of all Exchange mailboxes that includes details of the OU the user account is in. I seem to be able to get it to list everything except the OU.<\/p>\n
Can anyone enlighten me please?<\/p>","upvoteCount":4,"answerCount":8,"datePublished":"2016-02-08T11:56:10.000Z","author":{"@type":"Person","name":"paulowen7836","url":"https://community.spiceworks.com/u/paulowen7836"},"acceptedAnswer":{"@type":"Answer","text":"
\n```\n#Run from Exchange Server with RSAT or workstation with RSAT and implicit remoting to Exchange.\n\n#Next line not needed for PowerShell 3.0+\nImport-Module ActiveDirectory\n\n$Users = Get-ADUser -Filter * -Properties DistinguishedName,Title,LastLogonDate,Enabled,LegacyExchangeDN | Where-Object LegacyExchangeDN\n\n$Info = @()\n\nForEach ($User in $Users) {\n $OU = ([adsi]\"LDAP://$($user.DistinguishedName)\").parent\n $MailboxInfo = Get-Mailbox -Identity $user.SamAccountName \n\n $Item = New-Object -TypeName PSObject -Property @{\n Displayname = $MailboxInfo.DisplayName;\n Account = $User.SamAccountName\n Title = $User.Title\n AccountEnabled = $User.Enabled\n LastLogonDate = $User.LastLogonDate\n OU = ($OU -split \"LDAP://\")[1];\n Database = $MailboxInfo.Database;\n ServerName = $MailboxInfo.ServerName\n }\n $Info += $Item \n}\n$Info | Out-GridView\n```\n\n<\/code><\/pre>\nDuke’s example brings only AD account information - this one should merge the mailbox and AD info only if the account has a LegacyExchangeDN value.<\/p>","upvoteCount":1,"datePublished":"2016-02-08T12:55:10.000Z","url":"https://community.spiceworks.com/t/exchange-2010-powershell/471247/5","author":{"@type":"Person","name":"Rob-Dunn","url":"https://community.spiceworks.com/u/Rob-Dunn"}},"suggestedAnswer":[{"@type":"Answer","text":"
I’ve looked everywhere I can to find an answer to this, but come up empty, so maybe someone can put me on track.<\/p>\n
I want to export a CSV of all Exchange mailboxes that includes details of the OU the user account is in. I seem to be able to get it to list everything except the OU.<\/p>\n
Can anyone enlighten me please?<\/p>","upvoteCount":4,"datePublished":"2016-02-08T11:56:10.000Z","url":"https://community.spiceworks.com/t/exchange-2010-powershell/471247/1","author":{"@type":"Person","name":"paulowen7836","url":"https://community.spiceworks.com/u/paulowen7836"}},{"@type":"Answer","text":"
Import-Module ActiveDirectory \nGet-ADUser -filter * | select SamAccountName,DistinguishedName | export-csv c:\\wherever\\DN.csv\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2016-02-08T12:14:00.000Z","url":"https://community.spiceworks.com/t/exchange-2010-powershell/471247/2","author":{"@type":"Person","name":"dukemcawesome","url":"https://community.spiceworks.com/u/dukemcawesome"}},{"@type":"Answer","text":"Thanks Duke - is there any way to get this information out of Exchange at the same time I do a mailbox stats export?<\/p>\n
It used to be so easy from Exchange to just export the window content. Whilst powershell is obviously much more powerful, doing simple things with it seems so much more difficult!<\/p>","upvoteCount":0,"datePublished":"2016-02-08T12:25:24.000Z","url":"https://community.spiceworks.com/t/exchange-2010-powershell/471247/3","author":{"@type":"Person","name":"paulowen7836","url":"https://community.spiceworks.com/u/paulowen7836"}},{"@type":"Answer","text":"
What kind of information do you want from Exchange? Mailbox database, server, etc.?<\/p>","upvoteCount":0,"datePublished":"2016-02-08T12:51:14.000Z","url":"https://community.spiceworks.com/t/exchange-2010-powershell/471247/4","author":{"@type":"Person","name":"Rob-Dunn","url":"https://community.spiceworks.com/u/Rob-Dunn"}},{"@type":"Answer","text":"
Oh I see! I did think I might be missing the point a bit, lol.<\/p>","upvoteCount":0,"datePublished":"2016-02-08T12:58:50.000Z","url":"https://community.spiceworks.com/t/exchange-2010-powershell/471247/6","author":{"@type":"Person","name":"dukemcawesome","url":"https://community.spiceworks.com/u/dukemcawesome"}},{"@type":"Answer","text":"
Perfect - thank you very much Rob.<\/p>","upvoteCount":1,"datePublished":"2016-02-08T12:59:41.000Z","url":"https://community.spiceworks.com/t/exchange-2010-powershell/471247/7","author":{"@type":"Person","name":"paulowen7836","url":"https://community.spiceworks.com/u/paulowen7836"}},{"@type":"Answer","text":"