Solved

cannot save info to a file

Posted on 2015-02-12
6
88 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 40

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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 40

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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lotus Notes – formerly IBM Notes – is an email client application, while IBM Domino (earlier Lotus Domino) is an email server. The client possesses a set of features that are even more advanced as compared to that of Outlook. Likewise, IBM Domino is…
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
how to add IIS SMTP to handle application/Scanner relays into office 365.

679 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