Menu

[ea00bd]: / util-dropFiles / DeleteDropFile.ps1  Maximize  Restore  History

Download this file

58 lines (57 with data), 1.6 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
Param (
[Parameter(Mandatory = $True)]
[String]
$fileName,
[Parameter(Mandatory = $False)]
[Switch]
$debugDelete = $False,
[Parameter(Mandatory = $False)]
[String]
$ninjaAgentScriptingPath = "C:\ProgramData\NinjaRMMAgent\scripting\"
)
#
# for reference
#
# Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy Bypass -Force
#
################################################################
#
# Functions
#
Function MainDelete {
DeleteDropFile $fileName
}
#
#####
#
# DeleteDropFile
#
# Notes: This is not a -Force deletion (override read-only, etc., nor is it -Recurse and no wildcards.
# Feel free to add these as optional command switches to the function! -pat :)
#
Function DeleteDropFile ([String]$fileName) {
if ($debugWrite) {Write-Host "fileName = " $fileName}
$absPath = $ninjaAgentScriptingPath + $fileName
if ($debugWrite) {Write-Host "ninjaAgentScriptingPath = " $ninjaAgentScriptingPath}
if ($debugWrite) {Write-Host "absPath = " $absPath}
if (Test-Path -Path $absPath) {
if ($debugWrite) {Write-Host "File EXISTS, will delete..."}
# Remove-Item does NOT return anything after trying, so we test for file *after* command:
Remove-Item -Path $absPath
if (Test-Path -Path $absPath -eq $False) {
if ($debugWrite) {Write-Host "File " $absPath " successfully deleted!"}
} else {
if ($debugWrite) {Write-Host "FAILED TO DELETE FILE " $absPath}
} # end if(-NOT...
} else {
if ($debugWrite) {Write-Host "File does NOT exist!"}
} # end if (Test-Path...
} # end Function CreateDropFile...
#
#####
#
# Main()
#
MainDelete
#
#####
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.