A regular topic in #api β so this one had to be tackled!
This PowerShell script automates the relocation of devices in NinjaOne. It checks whether a device is located in a specified onboarding location and whether the custom field OnboardingDone is set to true. If both conditions are satisfied, the device is moved to a specified target location within the same organization.
IT teams often onboard devices to a temporary location such as "Onboarding", but forget to update the location after setup is complete. This leads to:
- β Incorrect policy assignment
- π Inaccurate reporting
- ποΈ Cluttered inventory
By automating the move process, this script ensures device location data remains accurate and clean β saving time and reducing errors.
- π¨βπ» IT Administrators: Eliminates manual post-onboarding tasks
- π οΈ MSPs: Maintains accurate inventories across multiple clients
- π€ Automation teams: Seamlessly integrates with NinjaOne automation flows
| Endpoint | Purpose |
|---|---|
POST /ws/oauth/token |
Authenticate using client credentials from custom fields |
GET /api/v2/devices?expand=location,organization |
Retrieve all devices with location and org details |
GET /api/v2/device/{deviceId}/custom-fields |
Read the OnboardingDone field |
GET /api/v2/organization/{orgId}/locations |
Get available locations for a given org |
PATCH /api/v2/device/{deviceId} |
Move the device to a new location |
Create the following Script Variables in NinjaOne (type: String/Text):
homelocationβ default:"Onboarding"targetlocationβ default:"Main Office"
These are injected at runtime via $env:homelocation and $env:targetlocation and can be set per policy or left at default.
This script uses secure authentication and custom fields based on the Getting Started guide by Luke Whitelock:
- π
NinjaOneAPIClientID - π
NinjaOneAPISecret - β
OnboardingDone(checkbox)
To set
OnboardingDoneto true from another automation:
Ninja-Property-Set onboardingdone 1This script is intended for use in a NinjaOne automation policy. Devices in the "Onboarding" location with OnboardingDone = true will be automatically moved to "Main Office" within the same organization.
π Author: Robert van Oorschot β Advance Your IT π Date: 2025-05-26 π·οΈ Version: 2.0.0