---
updatedAt: 2025-08-14T13:33:03.000Z
agentTools:
  siteIndex: https://developer.n-able.com/llms.txt
  projectIndex: https://developer.n-able.com/n-central/llms.txt
---

# NC Rest API - List all Customers and Sites

```powershell PowerShell
###########################################################################################
# This script will retrieve a list of all customers and sites                             #
# The list is sorted by CustomerName                                                      #
# The list contains the orgUnitId, CustomerName, SiteName, orgUnitType, parentI           #
# You can also export this information to CSV by removing the hash on the Export-CSV line #
###########################################################################################

function NCentral-OrgUnits {
    param (
        [string]$apiUrl,
        [string]$accessToken
    )

    # Build the URI for the API endpoint
    $uri = "$apiUrl/api/org-units"

    # Build the headers with the access token
    $headers = @{
        "Authorization" = "Bearer $accessToken"
    }

    # Send the GET request to retrieve org units information
    $response = Invoke-RestMethod -Uri $uri -Method Get -Headers $headers

    # Return the registration token details
    return $response.data
}


# Retrieve the org units
$Orgunits = NCentral-OrgUnits -apiUrl $apiUrl -accessToken $accessToken

# Create a list to store the modified output
$Result = @()

# Iterate through each org unit, excluding orgUnitId 50
foreach ($orgUnit in $Orgunits | Where-Object { $_.orgUnitId -ne 50 }) {
    # Determine the CustomerName and SiteName based on orgUnitId and parentId
    if ($orgUnit.parentId -eq 50) {
        # If parentId is 50, treat orgUnitName as the CustomerName
        $CustomerName = $orgUnit.orgUnitName
        $SiteName = ""
    } else {
        # Find the parent org unit to get the CustomerName
        $parentOrgUnit = $Orgunits | Where-Object { $_.orgUnitId -eq $orgUnit.parentId }
        if ($parentOrgUnit) {
            $CustomerName = $parentOrgUnit.orgUnitName
            $SiteName = $orgUnit.orgUnitName
        } else {
            $CustomerName = "Unknown"
            $SiteName = $orgUnit.orgUnitName
        }
    }


    # Add the result to the list
    $Result += [PSCustomObject]@{
        orgUnitId                   = $orgUnit.orgUnitId
        CustomerName                = $CustomerName
        SiteName                    = $SiteName
        orgUnitType                 = $orgUnit.orgUnitType
        parentId                    = $orgUnit.parentId
    }
}

# Sort the result by CustomerName
$SortedResult = $Result | Sort-Object CustomerName

# Display the sorted result in a formatted table with column width adjustments
$SortedResult | ft

# Uncomment the line below to export the result to a CSV file
#$SortedResult | Export-Csv -Path C:\Temp\ListAllCustomersAndSites.csv -NoTypeInformation
```

```json Response Example
{"success":true}
```

# Function to get orgunit list

<!-- powershell@8-27 -->



# Get list of org units

<!-- powershell@30-31 -->



# Loop through org units and populate results

<!-- powershell@37-64 -->



# Sort and Display results

<!-- powershell@66-73 -->