-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemove-OnRequest.ps1
More file actions
64 lines (57 loc) · 1.93 KB
/
Remove-OnRequest.ps1
File metadata and controls
64 lines (57 loc) · 1.93 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<#
.SYNOPSIS
Used for the remove files or folders from Explorer.
.DESCRIPTION
Used for the remove files or folders from Explorer. However remove items from either directly using file path, files which contain a list of file paths, directory, and Object which contains a list of the path.
.PARAMETER Path
Optional, Value can be either file or folder full path and remove it from the system if a path exists.
.PARAMETER FilePath
Optional, Value can be a file path in which data contains a list of paths. Read paths from file and remove every from the system one by one if it exists.
.PARAMETER ObjectList
Optional, Value can be the object and holds a list of file paths, Remove list of files one by one if exists.
.EXAMPLE
Remove-OnRequest -Path "D:/XML/RemoveMe.xml"
Remove-OnRequest -FilePath "D:/XML/RemoveMe.txt"
Remove-OnRequest -ObjectList @()
#>
function Remove-OnRequest() {
[cmdletbinding()]
Param (
$Path,
$FilePath,
$ObjectList
)
Begin {
}
Process {
try {
if ($null -ne $Path) {
if (Test-Path $Path) {
Remove-Item -LiteralPath $Path -Force -Recurse
}
}
elseif ($null -ne $FilePath) {
Get-Content $FilePath | ForEach-Object {
if (Test-Path $_) {
Remove-Item $_
}
}
}
elseif ($ObjectList.Count -gt 0) {
$ObjectList | ForEach-Object {
if (Test-Path $_) {
Remove-Item $_
}
}
$ObjectList = @();
}
}
catch {
Write-Exception -ErrorObj $_ -Message "Throws an exception in 'Remove-OnRequest'" -Stop $true
}
finally{
}
}
End {
}
}