Solved

cannot save info to a file

Posted on 2015-02-12
6
90 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
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Unified and professional email signatures help maintain a consistent company brand image to the outside world. This article shows how to create an email signature in Exchange Server 2010 using a transport rule and how to overcome native limitations …
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…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…

695 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