I'm trying to close certain open files on a remote 2008 R2 fileserver with the following lines:
$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 }
}
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.
I've verified that the $FileList
variable gets filled ($fid
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.