?
Solved

cannot save info to a file

Posted on 2015-02-12
6
Medium Priority
?
91 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Four New Appliances. Same Industry-leading Speeds.

But don't take it from us.  The Firebox M370 is Miercom tested and Miercom approved, outperforming its competitors for stateless and stateful traffic throughput scenarios.  Learn more about the M370, M470, M570 and M670 and find the right solution for your organization today!

 
LVL 40

Accepted Solution

by:
footech earned 2000 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This article will help to fix the below errors for MS Exchange Server 2013 I. Certificate error "name on the security certificate is invalid or does not match the name of the site" II. Out of Office not working III. Make Internal URLs and Externa…
In this video we show how to create a Shared Mailbox 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 >> Sha…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses

770 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