Powershell script to identify active users who have enrolled their device in JAMF

smantry
New Contributor

Hi everyone,
I am trying to figure if we can write something in powershell to query all the active users associated to a device enrolled in JAMF. Trying to setup some automation on a Windows box. Any helpinsight will be highly appreciated.

4 REPLIES 4

ooshnoo
Valued Contributor

I’d think MySQL queries would be the more logical route. Jamf doesn’t utilize anything close to power shell.

cbrewer
Valued Contributor II

I'm pretty sure it can be done. You'll need to get familiar with the API.

Look into using PowerShell's Invoke-RestMethod for the PowerShell piece.

tlarkin
Honored Contributor

yeah you will have to look at the API and look at PS cmdlets for interacting with APIs. PowerShell is a complete language and it has HTTP libs in it. There are multiple ways to interact with a REST API though in PS. There is Invoke-RestMethod and there is also Invoke-WebRequest. Both have slightly different use cases. PowerShell, in my limited experience with the language thus far, seems to always give you several options, each with different uses or edge cases they are not good for, or are perfect for. So, you'll have to do some testing.

tlarkin
Honored Contributor

I did a very quick and dirty test based off the MSFT docs

$uri = 'https://yourjamfserver.com/JSSResource/categories'
$creds = "user:password"                                                                  
$encodedcreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($creds))                
$headers = @{ Authorization = "Basic $encodedcreds" }                                                           
$data = Invoke-RestMethod -Uri $uri -Method Get -Headers $headers -UseBasicParsing                                      
$data                                                                                                           
xml                            categories
---                            ----------
version="1.0" encoding="UTF-8" categories

$data.InnerXML

When I ran $data.InnerXML it printed the output in the PS terminal