我试图在脚本运行后将其删除,但我收到一条错误消息,提示该文件正在使用中,我该怎么办?
$exclude = @("*.zip", "*.dll", "*.exe")
Get-ChildItem "C:\.." -Recurse -Exclude $exclude | Remove-Item -Force -Recurse -WhatIf
Remove-Item $PSScriptRoot -Force
最佳答案
据我所知,$PSScriptRoot
是脚本所在的目录。假设 PowerShell 3,你应该使用 $PSCommandPath
来调用脚本的完整路径:
Remove-Item $PSCommandPath -Force
关于脚本运行后 Powershell 自动删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61754695/