Elliottconnor2
Elliottconnor2

Reputation: 25

Export Powershell Object to CSV - Access Denied

I'm trying to get the permission of the calendar folder on a set user, then export it to a CSV, so we can easily view the permissions.

When I run this command:

Get-Mailbox |
    Get-MailboxPermission |
    Select-Object AccessRights, User, Identity, IsValid |
    Export-Csv -Path 'c:\Users\Connor\Desktop'

I get this error:

Export-Csv : Access to the path 'C:\Users\Connor\Desktop' is denied.
At line:1 char:89
+ ... hts,User,Identity,IsValid | Export-Csv -Path 'c:\Users\Connor\Desktop'
+                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OpenError: (:) [Export-Csv], UnauthorizedAccessException
    + FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.ExportCsvCommand

Upvotes: 2

Views: 3760

Answers (1)

KyleMit
KyleMit

Reputation: 30107

You need to make sure the PowerShell has write permission to the folder you're trying to write to. You can do this by

  1. Relaunching Powershell as Administrator
  2. Specifying a folder that PS can write to without elevated permissions
    • Try C:\temp\ (plus your filename.csv)
    • Or call Path.GetTempPath in PS with [System.IO.Path]::GetTempPath()

See Also: Export-Csv - Access to the path 'C:\export.csv' is denied

Upvotes: 1

Related Questions