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
#
#####