Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I close all open network files in PowerShell? [closed]

I'm trying to convert my old BAT script to PowerShell version, but after one hour googling I have no idea how to do it.

I'm looking for a structure very similar to the old one, find open net files, get its PID and close it.

BAT:

for /f "skip=4 tokens=1" %a in ('net files ^| findstr C:\Apps\') do net files %a /close

PowerShell?

like image 797
Widmo Avatar asked Feb 03 '13 12:02

Widmo


1 Answers

Here's another way. I like that it relies more on pipelining, which is the idiom of PowerShell:

net files | 
    where   { $_.Contains( "D:\" ) } |
    foreach { $_.Split( ' ' )[0] }   |
    foreach { net file $_ /close }
like image 149
Jay Bazuzi Avatar answered Sep 20 '22 02:09

Jay Bazuzi