-
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathRemove-Locked.ps1
More file actions
31 lines (23 loc) · 721 Bytes
/
Remove-Locked.ps1
File metadata and controls
31 lines (23 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<#
.SYNOPSIS
Remove a System-owned file or directory or a directory containing
a path that is too long.
.PARAMETER name
The path of the file or directory to remove.
.DESCRIPTION
For file and directories, the first attempt is to take ownership
of all objects, change ACL (access control lists) and then delete.
Additionally, for directories, will use "robocopy empty" method
of overwriting directory containing gratuitously long paths.
#>
param ([string] $name)
if (!(Test-Elevated (Split-Path -Leaf $PSCommandPath) -warn)) { return }
Set-ItemOwner $name
if ((Get-Item $name) -is [System.IO.DirectoryInfo])
{
Remove-Item $name -Force -Confirm:$false -Recurse
}
else
{
Remove-Item $name -Force -Confirm:$false
}