Tell me more ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to have a CSV file for all users in a specific Organizational Unit and have that for all OU's witin the domain /forest

Will the following work and/or where would I improve and/or change the script?

$OutputFile = 'C:\Users\Public\Documents\OuStructure.txt'
$InputtFile = 'C:\Users\Public\Documents\MailboxStatistics-'+(Get-Content $OutputFile).ToString+'.csv'

Foreach ($GetOu in (Get-Content $OutputFile)) {Get-Mailbox -ResultSize Unlimited |Where-Object {$_.OrganizationalUnit -like $GetOu -and $_.Database -notlike 'DB0*' } |Select-Object DisplayName,Alias,OrganizationalUnit,Database,PrimarySMTP*,Recipient* |Sort-Object OrganizationalUnit ` |Export-Csv -Path $InputtFile}

Cheers, Andor

share|improve this question
Perhaps I am looking at this from a 'difficult' angle and the possibility exists to achieve this easier? – Andor Oct 24 '12 at 10:25

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.