Solved

cannot save info to a file

Posted on 2015-02-12
6
81 Views
Last Modified: 2015-02-12
I have this command here but having problems getting the output to save to a file


ForEach ($mbx in (Get-Mailbox -Resultsize Unlimited | Select Identity)) {Get-MailboxPermission $mbx.Identity -User "domain\useraccount" | ? {$_.AccessRights -m
atch "FullAccess" -and $_.IsInherited -eq $False} | export-csv <directory> -nti}
0
Comment
Question by:techdrive
  • 2
  • 2
  • 2
6 Comments
 
LVL 24

Expert Comment

by:VB ITS
ID: 40606766
You need to specify a filename with Export-CSV and not just the directory. e.g. Export-CSV D:\Folder\Output.csv -nti
0
 
LVL 39

Expert Comment

by:footech
ID: 40606922
Since your Export-CSV command is inside a loop, you'll want to make sure that either:
 a) the filename is dynamic so each loop gets its own file
 b) if you're using PS 3.0+, you can use the -Append parameter with a static filename so that the file is not overwritten each time through the loop.

Just for completeness I will mention that there are other options as well for moving the export outside of the loop.
0
 

Author Comment

by:techdrive
ID: 40606925
footech can you show or tell me what syntax I am missing to export outside of the loop. I am using powershell 3.0
0
Free book by J.Peter Bruzzese, Microsoft MVP

Are you using Office 365? Trying to set up email signatures but you’re struggling with transport rules and connectors? Let renowned Microsoft MVP J.Peter Bruzzese show you how in this exclusive e-book on Office 365 email signatures. Better yet, it’s free!

 
LVL 39

Accepted Solution

by:
footech earned 500 total points
ID: 40606971
Two options:
- one with the foreach statement - you can surround it by array notation (or also sub-expression) and pipe the array to Export-CSV
- one with the ForEach-Object cmdlet - which takes pipeline input and outputs to the pipeline.  In the second I also expanded the property so that I wouldn't later have to reference it by name.
@(ForEach ($mbx in (Get-Mailbox -Resultsize Unlimited | Select Identity))
{
    Get-MailboxPermission $mbx.Identity -User "domain\useraccount" |
     ? {$_.AccessRights -match "FullAccess" -and $_.IsInherited -eq $False} 
}) | Export-Csv somefile.csv -nti

Get-Mailbox -Resultsize Unlimited | Select -expandProperty Identity | ForEach-Object `
{
    Get-MailboxPermission $_ -User "domain\useraccount" |
     ? {$_.AccessRights -match "FullAccess" -and $_.IsInherited -eq $False} 
} | Export-Csv somefile.csv -nti

Open in new window

0
 

Author Comment

by:techdrive
ID: 40607005
awesome thanks footech
0
 
LVL 24

Expert Comment

by:VB ITS
ID: 40607016
Good eye footech. I missed that the Export-CSV command was inside the loop!
0

Featured Post

Too many email signature changes to deal with?

Are you constantly being asked to update your organization's email signatures? Do they take up too much of your time? Wouldn't you love to be able to manage all signatures from one central location, easily design them and deploy them quickly to users. Well, you can!

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
In this video we show how to create a Contact in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Contact ta…
In this video we show how to create an email address policy in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Mail Flow…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now