Forum Discussion

NPleazy's avatar
NPleazy
Copper Contributor
Jul 29, 2021

Saving a file to a folder: Access to the path is denied

I'm getting an error related to not having access to a path on my virtual AWS machine. My profile is administrator

 

I deal with PHI so I redacted any evidence of where I work or the vendors that I'm pulling data from.

 

Here is my powershell command:

 

Invoke-RestMethod 'https://web.*Redacted*.com/api/dataexport/download/*Redacted*' -Headers @{'*Redacted*'} >> C:\Users\pbigateway\OneDrive - *Redacted*\Documents\*Redacted*_Report_APIs\PBI_Dashboard\Daily/$(Get-Date -format "yyyy.MM.dd.HH.mm").csv

 

Error:

 

out-file : Access to the path 'C:\Users\pbigateway\OneDrive' is denied.
At C:\Scripts\PBI_Dashboard_00.ps1:1 char:257
+ ... t_APIs\PBI_Dashboard\Daily/$(Get-Date -format "yyyy.MM.dd.HH.mm").csv
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (:) [Out-File], UnauthorizedAccessException
+ FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand

  • NPleazy, the error message states that you don't have access to C:\Users\pbigateway\OneDrive.

     

    This happens because your path contains spaces, you should place it between quotes so Powershell knows about the complete path. it would look like this. Take not of the quotes: '

    Invoke-RestMethod 'https://web.*Redacted*.com/api/dataexport/download/*Redacted*' -Headers @{'*Redacted*'} >> 'C:\Users\pbigateway\OneDrive - *Redacted*\Documents\*Redacted*_Report_APIs\PBI_Dashboard\Daily/$(Get-Date -format "yyyy.MM.dd.HH.mm").csv'

    And as farismalaeb already mentioned, the forward slash won't work. A filename cannot contain any slashes. So you should change the forward slash (/) to a backslash (\). The csv file will be downloaded to the Daily folder.

     

    Grtz Ruud

Resources