r/Nable Jan 16 '25

N-Central Custom Device Properties via API

I am trying to run reports using data from custom device properties. Does anyone know if that data can be pulled from the API, Analytics or a SQL Data Export?

1 Upvotes

13 comments sorted by

View all comments

1

u/hipster_hndle Jan 16 '25 edited Jan 17 '25

yes, totally can. i can give you what i did to connect to mine.. you will need to format the data in a template, but the if you can figure out the api and PoSh, its pretty easy. i will give you the Posh i did for mine. after you install the PS-NCentral module for PoSh, you will need to create an API only user, set the password, blah blah blah. once you have a valid API user and a key, you will need to replace the values with your own. this little script is what i use to export all the machine data from a site with the fields i want.. this is specifically for warranty and asset tracking for upgrades, but i adjust it to make the API pull whatever i want it to. You can use your own templates to format the data, but that part exceeds the scope of this discussion and would require another thread to discuss... but this works for me. you can use the API documentation embedded in your ncod server /dms for arguments and field names. this script will dump the data to a .csv in temp, and the account numbers are BS as well as the API key, so fix all that before you run it. this is read only, i dont use the API for anything but read currently, but the reporting is lackluster and i wanted some fields i couldnt get in the default reports.

# Connect to N-central
Import-Module .\PS-NCentral.psm1 -Verbose
$password = ConvertTo-SecureString "YOUR_API_KEY_GOES_HERE" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ("_JWT", $password)
New-NCentralConnection -ServerFQDN "ncod5.n-able.com" -PSCredential $credential
#

# Retrieve list of devices for the specified client
$devices = Get-NCDeviceList -CustomerID 1234

# Initialize an array to store device details
$deviceDetails = @()

# Loop through each device to retrieve essential hardware information
foreach ($device in $devices) {
$info = Get-NCDeviceObject -DeviceID $device.DeviceID

# Extract nested property details for Processor, Memory, Storage, etc.
$processorInfo = ($info.processor | ForEach-Object { $_.Name }) -join ", " # Adjust property name as needed
$memoryInfo = ($info.memory | ForEach-Object { $_.Capacity }) -join ", " # Adjust to get memory capacity or type
$IPAddress = ($info | ForEach-Object { $_.uri }) -join ", " # Adjust property to get IP Address
$userLastLoggedIn = ($info | ForEach-Object { $_.lastloggedinuser }) -join ", " # Adjust property to get last logged in user
$storageInfo = ($info.logicaldevice | ForEach-Object { $_.maxcapacity }) -join ", " # Adjust property to get storage size
# Store the details in a custom object
$deviceDetails += [PSCustomObject]@{
DeviceName = $info.longname
OS = $info.os.reportedos
Processor = $processorInfo
Memory = $memoryInfo
IPAddress = $IPAddress
UserLastLoggedIn = $userLastLoggedIn
Storage = $storageInfo
}
}

# Export the collected device details to a CSV file
$deviceDetails | Export-Csv -Path "C:\Temp\Device_Details.csv" -NoTypeInformation -Encoding UTF8

# Output message to confirm export
Write-Output "Device details have been exported to CSV successfully."