Link to home
Start Free TrialLog in
Avatar of Simon Allaway
Simon AllawayFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Powershell scripts that exports results to a CSV

Morning All experts

I need a scripts that can run against the entire exchange database that reports the full access rights of users which then exports to a csv file.

I also need the same for the send as permission.  I have the scripts to run against a individual  user but would really like to generate a report for the whole organisation.

Thanks everyone who looks at this question.  I just hope its not to hard.

Regards

Simon
Avatar of Mohammed Khawaja
Mohammed Khawaja
Flag of Canada image

Avatar of Simon Allaway

ASKER

So would it be something like this for send permission:

Get-Mailbox | Get-ADPermission | where {($_.ExtendedRights -like “*Send-As*”)} | FT –Wrap | Export-csv C:\permissions.csv

and this for full

Get-MailboxPermission –identity * | fl user, identity, accessrights| Export-csv C:\permissions.csv


??????

Thanks

Si
cybersi, you never apply a format-* cmdlet prior to exporting. The format-* cmdlets generate text, and there is no relation to the info they are applied to. Use them only for screen output.

If you want to filter the properties to export, use select-object instead, and for checking what will be in a CSV, pipe to convertto-csv:
Get-MailboxPermission * | select User, Identity, AccessRights | convertto-csv

Open in new window

and bang, we are lost. AccessRights is an array, and you will not see the values :(
Somehow we need to unroll the array, and decide what to display. Luckily, we don't need more than just the name of the privileges, and so:
Get-MailboxPermission * | select User, Identity, @{n='AccessRights'; e={$_.AccessRights -join ","}} | convertto-csv

Open in new window

Replace ConvertTo-CSV with Export-CSV if you are satisfied.

The "Send As" part is similar. You should restrict to the properties necessary; it doesn't make sense to export the AD privileges (again, those are an array) and such.
Hi many thanks  for the above. I will try the above when I get in the office. It just goes to show how powerful power shell is if u know what you are doing. I would be lying if I Said I understand the syntax but I guess hopefully the more I use it eventually things will just click. I know its kinda sad but I do enjoy learning things like this. Was the same with HTML.
Morning Qlemo

Great it works only problem is it reports back that i need to use the  "-ResultSize Unlimited" as only reports back the first 1000 entries.

with regard to the "send as" dor i just replace the 'access rights' with send as like this

Get-MailboxPermission * | select User, Identity, @{n='send as'; e={$_.sendd as -join ","}} | convertto-csv

?

Also it prompts for the path to the csv when usiing export-csv  can I just add the path at the end of the string for example export-csv c:\output.csv

?

Thanks again

Simon
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial