Menu

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

Download this file

57 lines (56 with data), 1.8 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
Param (
[Parameter(Mandatory=$True)]
[String]
$fileName,
[Parameter(Mandatory=$False)]
[Switch]
$debugRead = $False,
[Parameter(Mandatory=$False)]
[String]
$ninjaAgentScriptingPath = "C:\ProgramData\NinjaRMMAgent\scripting\"
)
#
# for reference
#
# Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy Bypass -Force
#
######################################################################
#
Function MainRead {
ReadDropFile $fileName
}
#
#####
#
Function ReadDropFile ([String]$fileName) {
if ($debugRead) {Write-Host "fileName = " $fileName}
# assumed the scripting folder on each machine...
$absPath = $ninjaAgentScriptingPath + $fileName
if ($debugRead) {Write-Host "ninjaAgentScriptingPath = " $ninjaAgentScriptingPath}
if ($debugRead) {Write-Host "absPath1 = " $absPath}
if (Test-Path -Path $absPath) {
if ($debugRead) {Write-Host "File EXISTS reading..."}
# read text from drop file as JSON, converting to String/text:
$kvpsTemp = Get-Content -Path $absPath -Raw | ConvertFrom-Json
if ($debugRead) {Write-Host "GetType() from file read: " $kvpsTemp.gettype()}
if ($debugRead) {Write-Host "JSON converted to String: [" $kvpsTemp "]"}
# next convert text to PSCustomObject so we can use $obj.attribute syntax:
$kvps = ConvertFrom-Json -InputObject $kvpsTemp
if ($debugRead) {Write-Host "GetType() from conversion: " $kvps.gettype()}
if ($debugRead) {Write-Host "String() converted to PSCustomObject: [" $kvps "]"}
if ($debugRead) {Write-Host "a: " $kvps.a}
if ($debugRead) {Write-Host "b: " $kvps.b}
if ($debugRead) {Write-Host "c: " $kvps.c}
if ($debugRead) {Write-Host "d: " $kvps.d}
} else {
if ($debugRead) {Write-Host "File" $ninjaAgentScriptingPath$filename "does not exist!"}
}
}
#
#####
#
# Main()
#
MainRead
#
#####
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.