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?
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 }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With