Export-Csv to a hidden file

Welcome Forums General PowerShell Q&A Export-Csv to a hidden file

This topic contains 4 replies, has 4 voices, and was last updated by

4 years, 11 months ago.

  • Author
  • #12952

    Points: 0
    Rank: Member

    Sorry I couldn't find any topic related to this matter.
    When I try to use export-csv to an already existing, hidden file, I get the error. As you see I use -force switch.
    If I unhide the file it works well.

    Export-Csv : Access to the path 'E:\Users\ao\Desktop\result.csv' is denied.
    At line:1 char:13
    + Get-Process|Export-Csv -Path .\result.csv -force
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : OpenError: (:) [Export-Csv], UnauthorizedAccessException
    + FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.ExportCsvCommand

    the original command takes a while to output data to the csv file and I want it to be hidden so I created the file beforehand and hid it, as I couldn't find a switch for export-csv to hide the file when it creates it. there's no point hiding the file, as after export-csv is done, the file gets read and deleted which is happening far more faster.
    I want to hide the file during the output process.
    Any suggestion appreciated.


  • #12961

    Points: 0
    Rank: Member

    Don't think you can – that's the whole point of hidden files

  • #12965

    Points: 1,785
    Helping HandTeam Member
    Rank: Community Hero

    What's the goal in hiding it? To prevent another process from "seeing" it as it is created? In that case, create it in a different folder, and then move it when it's done.

  • #12974

    Points: 0
    Rank: Member

    Dynamically create a temp file, and as Don said, move it when you're done.

    PS foo:\> $path = [IO.Path]::GetTempFileName()
    PS foo:\> $path
    PS foo:\> Add-Content -Path $path "foo"
    PS foo:\> mv -Path $path -Destination c:\scripts\gilroy.txt
    PS foo:\> cat C:\Scripts\gilroy.txt
    PS foo:\>

  • #12979

    Points: 0
    Rank: Member

    Thank you guys. I was afraid there would be no way, but a workaround, but what to do? 🙂


The topic ‘Export-Csv to a hidden file’ is closed to new replies.