Skip to content

yourejuanito/Jamf-Pro-Site-Assignment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 

Repository files navigation

Corporate Computer Site Assignment Script

Screenshot

Overview

This Bash script allows IT administrators to assign a Jamf-managed macOS device to a specific Site using SwiftDialog for the user interface.

Instead of dynamically fetching sites via the Jamf API (which SwiftDialog currently struggles to display from JSON), this v1.0 version uses a static, predefined list of sites and their IDs. The selected site is then updated on the target Mac's Jamf record via the Jamf Pro API.

Author: Juan Garcia
Version: 1.0


Features

  • Displays a drop-down list of sites via SwiftDialog.
  • Pulls Computer ID (jssID) and Serial Number from a local plist file.
  • Uses Jamf's OAuth 2.0 flow for secure API authentication.
  • Sends a PATCH request to /api/v1/computers-inventory-detail/{id} to update the Site ID.
  • Sorts sites alphabetically while keeping IDs matched.
  • Deployment Workflow to use Jamf Pro with.

Requirements

  • macOS
  • SwiftDialog installed at /usr/local/bin/dialog
  • jq installed for JSON parsing
  • Jamf Pro instance with API access
  • A local plist file containing:
    • jssID (Jamf Computer ID)
    • serialNumber (Mac serial number)
    • More information on creating - (rtrouton)
  • Jamf API Client ID and Client Secret
    • Jamf API Client ID with a Role that has the ability to Read, Create, and Update Computers.

Installation for local testing

  1. Install SwiftDialog:
    brew install --cask swift-dialog
  2. Install jq:
    brew install jq
  3. Place the script in your desired location (e.g., /usr/local/bin/SwiftDialog-SiteAssignment.sh).
  4. Make it executable:
    chmod +x /usr/local/bin/SwiftDialog-SiteAssignment.sh
  5. Update the configuration variables in the script with you attributes:
    jamfURL="https://[yourjamfCloud].jamfcloud.com"
    client_id="[yourClientID]"
    client_secret="[yourClientSecret]"
    plistPath="[locationOfYourEndpointInformationPLIST]"

Usage

Run the script manually:

sudo /bin/bash /path/to/testingpolicy.sh

You’ll see the image from above.

  1. A SwiftDialog drop-down listing your available sites.
  2. Once a site is selected, the script updates the Site ID in Jamf for that Mac.

Example plist file

You can create a jamf configuration profile with a Applications & Custom Settings and upload the plist file below.

Your plist file should be located in the path set in plistPath and contain:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>jssID</key>
    <integer>123</integer>
    <key>serialNumber</key>
    <string>C02XXXXXXX</string>
</dict>
</plist>

API Endpoint Used

This script uses:

PATCH /api/v1/computers-inventory-detail/{id}

Payload:

{
  "general": {
    "siteId": [selectedID]
  }
}

Known Limitations

  • Static site list — Must be manually updated if sites change in Jamf. Sites don't tend to dynamically change that often, management for site names and id's is manual.
  • SwiftDialog JSON limitation — Currently cannot directly parse API-returned JSON into the drop-down.

Credits


License

MIT License — Use freely, modify, and share.

About

Updating Sites just got easier. Using swift dialog this script will allow you to update a computer with a new site from the OS. Great for multi-site organizations with one ABM instance.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages