如何关闭在PowerShell中的所有开放式网络的文件? [英] How do I close all open network files in PowerShell?
本文介绍了如何关闭在PowerShell中的所有开放式网络的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想我的老BAT脚本转换为PowerShell的版本,
了一小时后,谷歌搜索我不知道该怎么做。
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.
我正在寻找非常相似,旧的结构,发现开网的文件,
获得其PID并关闭它。
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的?
PowerShell?
推荐答案
净文件仍然是你最好的选择。尝试是这样的:
Net file is still your best bet. Try something like this:
$results = net file | Select-String -SimpleMatch "C:\Apps\"
foreach ($result in $results) {
#Get id
$id = $result.Line.Split(" ")[0]
#Close file
net file $id /close
}
这篇关于如何关闭在PowerShell中的所有开放式网络的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文