Search code examples
powershellwindows-server-2012

How to close a created file using powershell


I've written a powershell script and I use covertto-csv to dump the stuff into, that have read in my code. Once all the stuff is written to a csv file (which I created using covertto-csv), I use the same file as an argument for another program which I run from the same script. As an output a csv is created successfully but when another program access that csv, I get FileAccess error. How this can be solved?


Solution

  • You can solve this problem wiht 2 way :

    1. Copy your file to another place and then use it :

      Copy-Item -Path "somepath" -Destination "newpath"
      

      and then use it .

    2. stop process that use this file :

      get-process -name *Process name that using the file* | stop-process