## Set the temporary directory used for uploading to FTP site $TEMPDIR = "${Env:ProgramData}\Emberkom\Temp" If (! (Test-Path -PathType Container $TEMPDIR) ) { New-Item -ItemType Directory -Force -Path $TEMPDIR } ## Set the file name for the Ninja logs when it's uploaded $NINJALOGS = "{0}_{1}.cab" -f ${Env:ComputerName}, $(Get-Date -Format "yyyyMMdd-HHmmss") ## Get the NinjaRMM installation directory If (Test-Path "${Env:ProgramFiles(x86)}") { $INSTALLDIR = $(Get-ItemProperty -Path 'HKLM:\SOFTWARE\WOW6432Node\NinjaRMM LLC\NinjaRMMAgent' -Name Location).Location } Else { $INSTALLDIR = $(Get-ItemProperty -Path 'HKLM:\SOFTWARE\NinjaRMM LLC\NinjaRMMAgent' -Name Location).Location } ## Collect agent logs Start-Process -FilePath "${INSTALLDIR}\ninjarmmagent.exe" -ArgumentList "/collectlogs" -Wait ## Move ninjalogs.cab to $TEMPDIR Move-Item -Path "${Env:WINDIR}\Temp\ninjalogs.cab" -Destination "${TEMPDIR}\${NINJALOGS}" ## Upload to FTP