[CmdletBinding()] param ( [Parameter(Mandatory=$true)] [String] $Token ) <# .SYNOPSIS Install Ninja RMM .DESCRIPTION Download and install the Ninja RMM agent with the given token .PARAMETER Token Agent install token (required) .EXAMPLE .\Install-NinjaRmm.ps1 -Token '90a92722-da34-452c-99e0-af8be7fcbf0c' #> begin { $InstallerUrl = 'https://us2.ninjarmm.com/ws/api/v2/generic-installer/NinjaOneAgent-x86.msi' $InstallerPath = Join-Path -Path $env:TEMP -ChildPath 'NinjaOneAgent-x86.msi' } process { Write-Host "Installing Ninja RMM with token '$Token'..." # Download try { Write-Host "Downloading application..." $ProgressPreference = 'SilentlyContinue' [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12 # Use Legacy WebClient for compatibility (New-Object Net.WebClient).DownloadFile($InstallerUrl, $InstallerPath) } catch { throw "Failed downloading application. $_" } # Install try { Write-Host "Installing application..." Start-Process "C:\Windows\System32\msiexec.exe" -ArgumentList "/i `"$InstallerPath`" TOKENID=`"$Token`" /qn /L*V `"$($InstallerPath).log`"" -Wait Write-Host "Log saved at '$($InstallerPath).log'" # Get-Content "$($InstallerPath).log" } catch { throw "Failed installing application. $_" } } # Clean up end { if (Test-Path $InstallerPath) { Write-Host "Removing package download from '$InstallerPath'" Remove-Item -Path $InstallerPath -Force } }