title: invoke-command net file close
body: <p>I'm trying to close certain open files on a remote 2008 R2 fileserver with the following lines:</p>
  
  <pre><code>$FileList = Invoke-Command -Scriptblock { openfiles.exe /query /S fileserver01 /fo csv | where {$_.contains("sampletext")} }
  foreach ($f in $FileList) {
      $fid = $f.split(',')[0]
      $fid = $fid -replace '"'
      Invoke-Command -ComputerName fileserver01 -ScriptBlock { net file $fid /close }
  }
  </code></pre>
  
  <p>I can get this to work if I type it in, but when I throw it into a script, it doesn't close the files.</p>
  
  <p>I've verified that the <code>$FileList</code> variable gets filled (<code>$fid</code> indeed gets the file id), so I don't think there's a execution policy that's blocking me. I'm not sure what it could be.</p>