Out-file return Access denied

Hello, I used this script
$text | Out-File -FilePath $output\"header.csv"

The script was working fine but yesterday it started showing me an error: Access to the path was denied. Path is C:\users\my_profile\desktop\script\script.ps1

Can I help me?

Thank you.

What changed before yesterday? :wink:

There’s is probably little to no chance that we might be able to help you with the little information you gave.

You may share your code (not just one line) and you may share the complete error message, please.

And BTW: When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org <---- Click :point_up_2:t4: :wink:

You have a folder called script.ps1? If not, then that is not the path for $output

1 Like

I tried the script on another PC and it works fine there. There may have been a change in authorization at the powershell level example after update windows?

That is not a proper path, the double qoute should surround the entire string, not just the header.csv:

PS C:\> $output = 'C:\Scripts'
PS C:\> $output"\header.csv"
Line |
   1 |  $output"\header.csv"
     |         ~~~~~~~~~~~~~
     | Unexpected token '"\header.csv"' in expression or statement.

PS C:\> "$output\header.csv"