Solved

cannot save info to a file

Posted on 2015-02-12
6
82 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
In this video we show how to create a User 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 >> Mailb…
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…

910 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

17 Experts available now in Live!

Get 1:1 Help Now