-
Notifications
You must be signed in to change notification settings - Fork 0
/
Untitled1.ps1
38 lines (27 loc) · 994 Bytes
/
Untitled1.ps1
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
32
33
34
35
36
$FolderPath = '\\wwww345435345\fdsfsf$\sdfdgdg\sdfsdfsdf'
$splitted = ($FolderPath -split '\\').trim()
#Invoke-Expression -Command "rmtshare.exe $FolderPath"
Remove-Item $FolderPath -ErrorVariable blad -Recurse -ErrorAction SilentlyContinue
if (!$?)
{
if ($($blad.CategoryInfo.Category) -eq 'ObjectNotFound')
{
$blad.exception.Message | Write-Warning
}
if ($($blad.CategoryInfo.Category) -eq 'PermissionDenied')
{
" Manual action is required: $($blad.exception.Message)" | Write-Warning
}
else {$flase}
if($($blad.CategoryInfo.reason) -eq 'PathTooLongException')
{
Get-ChildItem $blad.targetObject -Directory |
foreach {
write-host "long path/name detected doing cleanup using alternative method"
$obj = new-object -ComObject scripting.filesystemobject
$paths = $(Join-Path -Path $($blad.CategoryInfo.TargetName) -ChildPath $_)
$obj.DeleteFolder($('\\?\'+$paths))
}
}
}