Deploy Ninja Agent using N-Able

I know Tom mentioned his staff had created a script that they kicked off from N-Able that setup those devices onto his Ninja One. I am working on creating this script for us, but it seems a little more confusing that I had thought. Usually, the RMM Vendor already has a script developed that will do this but the procedure that is published by Ninja One is to use PDQ Deploy at each site. This still means that we will need to “touch” domain controllers at every customer site (some of whom do not have domain controllers). Any insight on how someone would do this with a powershell script would be greatly appreciated. Where would you store your “Generated Ninja Agent(s)” so that they are secure? How does the the powershell script download and execute the installs silently without end-user interaction using the System Account that N-Able Agent is using?

Hello,

As it turns out, the download links for the Ninja Agent are not behind any kind of authentication so you can have your script download the installers directly from Ninja. (Please note that the links do expire when Ninja updates their agent version, this appears to coincide with Ninja dashboard updates). Also, the Ninja Agent works as a silent installer if called from command line, it does not require any user interaction.

I have the somewhat crude script that I used to manually run on workstations to download and install the Ninja Agent. This can be adapted to prompt for a variable (the agent URL) to use with N-Able’s automation manager but I found it to be unreliable so I just ran it manually via Remote Background. (I do not have access to the variable version of the script at this moment or I would post it as well).

To get your Ninja Agent URL you can go through the process to download the agent, wait for it to generate the agent and then when the download button appears just right click > copy link address. Paste that into the following script where is says URLTONINJAINSTALLERGOESHERE (leave the single quotes in the script) and run via PowerShell. After you confirm that the endpoint shows up in Ninja, you can delete the Ninja directory in the root of C:, or you could change the location to a temp directory if you would like.

New-Item -Path "C:\" -Name "Ninja" -ItemType "directory" ; cd 'C:\Ninja'; Start-BitsTransfer -Source 'URLTONINJAINSTALLERGOESHERE' -Destination 'C:\Ninja\agent.msi'; ./agent.msi
1 Like

Thank you so much LTS_Kyle! It seems to work great. Using your assistance, I am developing a small PS script for N-Able to pass the URL to the script using the parameters option when adding a automated task. My goal is that It downloads the agent to a temp folder and runs the install silently, writes out log file from MSI so you can review results, checks the exitcode to confirm result and then if failed writes “failed” result back to dashboard, if passed writes “successful” back to the dashboard and for security measures deletes the msi from the temp folder. I have it somewhat functional now. I just need to polish it up a bit and sanitize it and I will be posting it back here to share with anyone whom has the same needs. :wink: Thank you again my friend :slight_smile:

Here is what I have for my PowerShell script to install Ninja One RMM. Here is am using N-Able to deploy but it could be adapted to any RMM that would allow you to pass parameters to scripts. The only parameter required is the Ninja download URL for the corresponding Client/Site. I am a noob PowerShell scripter so be kind but honest with your comments and suggestions. :wink: I hope this helps someone out there :wink:

# Get URL to download Ninja Agent
# 1. Login to Ninja and click the plus sign at upper left
# 2. Click Add Device(s)
# 3. Choose Windows
# 4. Select Organization and Location
# 5. Click the [Generate Installer] button
# 6. Now at the bottom right-click Download Installer and choose copy link
# 7. Now add automated task to N-Able per Client/Site enter the copied URL as a parameter
# ---------------------------------------------------------------------------------------
 
Param(
  [string]$source
)

# Tip:
# Set the Managed Service Provider's Directory - keep as Temp or customize for your MSP
# Note we keep a PCS folder named after our MSP Business on every managed device root drive
# All scripts and techs work only from that folder
# This SOP makes it easy to schedule frequent clean up scripts and a more complete offboarding from MSP

# Define Variables
$MSPDir = "C:\Temp\" # IMPORTANT - add the trailing backslash character!
$destination = $MSPDir + "CurrentNinjaOneAgent.msi"
$DateStamp = (get-date).ToString("d.M.yyyy hh:mm tt")
$logfile = $MSPDir + "CurrentNinjaOneAgent.log"
$Arguments = "/i " + $MSPDir + "CurrentNinjaOneAgent.msi", "/quiet", "/norestart", "/L*v", $logfile

#Check for and Create Temp Folder if not exist
if(!(Test-Path -Path $MSPDir )){
    New-Item -ItemType directory -Path $MSPDir
    Write-Host "New ", $MSPDir "folder created"
}
else
{
  Write-Host $MSPDir, " Folder already exists"
}

#Download Agent using Bits - Good method for mass deployments (Bandwidth aware, pause & resume, etc.)
Start-BitsTransfer -Source $source -Destination $destination

# Start Install and wait until completed then get MSI ExitCode
$InstallMSI = Start-Process -FilePath C:\Windows\System32\msiexec.exe  -Wait -Passthru -ArgumentList $Arguments
$ExitCode = $InstallMSI.ExitCode

#Check if installation was successful or not
if(!($ExitCode -ne 0 )){
    Write-Host "Completed Installation: ", $DateStamp
    Write-Host "Install Successful"
    Write-Host "MSI Installation ExitCode: ", $ExitCode
    Write-Host "----------------------------------------------------------------------------------------------"
    Write-Host "The agent installation file has been deleted"
    Write-Host "Test Ninja RMM Agent"
    Write-Host "----------------------------------------------------------------------------------------------"
    Write-Host "Remove device from N-Able by deleteing from N-Able dashboard or use UninstallN-Able.ps1 script"
    Remove-Item -Path $destination
}
else
{
    Write-Host "Completed Installation: ", $DateStamp
    Write-Host "Install Failed!"
    Write-Host "MSI Installation ExitCode: ", $ExitCode
    Write-Host "----------------------------------------------------------------------------------------------"
    Write-Host "https://docs.microsoft.com/en-us/windows/win32/msi/error-codes"
    Write-Host "Review the link above to determine the error code from the MSI installation"
    Write-Host "----------------------------------------------------------------------------------------------"
    Write-Host "Consider installing the agent locally"
    Write-Host "Find the setup file here: ", $destination
}

Write-Host "Please review the log file: ", $logfile

exit 0