【发布时间】:2019-01-17 18:20:40
【问题描述】:
我是 PowerShell 新手,我一直在尝试创建一个脚本,但到目前为止,我一直没有成功。我希望它完成一项特定任务,即;
我需要能够在驱动器中搜索名为 "Cookies" 的特定文件夹并将其删除。问题只是文件夹 cookie 设置在多个位置。
例子:
\\\myserver\test\User\Profiles\USER1\AppData\Roaming\Microsoft\Windows\Cookies
\\\myserver\test\User\Profiles\USER2\AppData\Roaming\Microsoft\Windows\Cookies
\\\myserver\test\User\Profiles\USER3\AppData\Roaming\Microsoft\Windows\Cookies
\\\myserver\test\User\Profiles\USER4\AppData\Roaming\Microsoft\Windows\Cookies
继续……
如何让 powershell 通过所有不同的 USER 文件夹搜索 Cookies 文件夹并将其删除。
我想出了这个,但我希望 powershell 大师可以帮助我。
$cookies= Get-ChildItem \\myserver\test\User\Profiles\*\AppData\Roaming\Microsoft\Windows\Cookies
foreach ($cookie in $cookies){
Remove-Item "$cookies" -Force -Recurse -ErrorAction SilentlyContinue
}
这行得通吗?
【问题讨论】:
标签: powershell