脚本运行后 Powershell 自动删除

标签 powershell

我试图在脚本运行后将其删除,但我收到一条错误消息,提示该文件正在使用中,我该怎么办?

$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/

相关文章:

mysql - 如何使用 PowerShell 2.0 在循环中运行带参数的不同 MySql 语句?

windows - 在 PowerShell 中,如何从所有 SID 的 HKEY_Users 中提取文件?

Powershell 将安全协议(protocol)设置为 Tls 1.2

azure - New-AzWebApp 选择 .NET Core 的堆栈设置

powershell - 检查文件夹是否也已完成复制

powershell忽略来自不同进程的输出的字符转义

powershell - 获取 wsp 部署到的站点 url

powershell - 无法从 Visual Studio 2012 登录 Azure

windows - 在 Powershell 中检测 Windows 8

c# - "Cannot Invoke this function because the current host does not implement it"