2

I am looking to output the results of

Get-Mailbox –Server MYserverName | Get-MailboxPermission | FL

piped into individual text files for each individual mailbox, with the text file named for the mailbox - e.g. I want to have a folder with the content:

  • C:\Example\MailboxUser1.txt
  • C:\Example\MailboxUser2.txt
  • C:\Example\MailboxUser3.txt

with each containing the mailbox permission results.

I know I can do a foreach loop along the lines of:

ForEach-Object {Out-file $_.name}

to generate the output files, but I'm not too sure how I would do this in a single step to get the permissions for all my mailboxes into individual files (I know this will give me a lot of text files!)?

Pimp Juice IT
  • 1,010
  • 1
  • 9
  • 16
AskJarv
  • 25
  • 6
  • I like McKenning's answer, but I'll add to this that I've used with great success this script: https://gallery.technet.microsoft.com/office/Generate-HTML-Report-for-da0f5132 to create an HTML file that is clickable and is great for sending to mgmt. – TheCleaner Dec 07 '15 at 17:41

2 Answers2

2

You are almost there. Combine them like so:

Get-Mailbox –Server MYserverName | % { Get-MailboxPermission $_ | FL | Out-file $_.name }

I tried this on my Exchange 2013 lab server and it seemed to do what you need. For this function, there is little difference between 2010 and 2013.

If you want the ".txt" extension on the output files, do this:

Get-Mailbox –Server MYserverName | % { Get-MailboxPermission $_ | FL | Out-file "$_.txt" }
McKenning
  • 220
  • 1
  • 3
  • 10
0

Thanks all - that was pretty close - but when I ran it on a couple of different 2010 servers I got an error:

Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently. + CategoryInfo : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [], PSInvalidOperationException + FullyQualifiedErrorId : RemotePipelineExecutionFailed

Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently. + CategoryInfo : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [], PSInvalidOperationException + FullyQualifiedErrorId : RemotePipelineExecutionFailed

which led me to http://mikepfeiffer.net/2010/02/exchange-management-shell-error-pipelines-cannot-be-executed-concurrently/ which suggested I use a variable - so my end result was:

$mailbox = Get-Mailbox
$mailbox | % { Get-MailboxPermission $_ | FL | Out-file "$_.txt" }

which worked perfectly! Thanks again!

AskJarv
  • 25
  • 6
  • Glad to hear it. Also, I guess there are some differences between 2010 and 2013 PS command structures. Now you and I both learned something! – McKenning Dec 07 '15 at 22:06