title: Running a PowerShell script in SQL Server Agent is not working
body: <p>I have a SQL Server Agent job that runs a PowerShell script to pull data from a database and save it in a csv file. </p>
  
  <p>The job type is set to <code>PowerShell</code> and the command looks like this:</p>
  
  <pre><code>$sql=@'exec my_stored_procedure'@
  $result = Invoke-Sqlcmd -ServerInstance INSTANCE_NAME -Database DBNAME -Query $sql
  #The first row gets removed and then save it to a csv file
  $result | ConvertTo-Csv -NoTypeInformation | Select-Object -Skip 1 | Set-Content \\SERVER\c$\Folder\file.csv
  </code></pre>
  
  <p>When I run this job, it runs successfully, but the <code>file.csv</code> is not created in the specified location. </p>
  
  <p>I checked the Job History and it says:</p>
  
  <blockquote>
    <p>The job script encountered the following errors. These error did not
    stop the script:  (.....) The corresponding line is   <code>$result |
    ConvertTo-Csv -NoTypeInformation | Select-Object -Skip 1 | Set-Content
    \\SERVER\c$\Folder\file.csv</code>. Correct the script and reschedule the
    job. The error information returned by PowerShell is <code>'Cannot use
    interface. The IContentCmdletProvider interface is not implemented by
    this provider.'</code>. Process Exit Code 0.</p>
  </blockquote>
  
  <p>Could someone help me understand what I'm missing?
  This is my first PowerShell project, so I'm probably missing things that are obvious to other people..?</p>