Skip to main content
Question

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


Forum|alt.badge.img+1

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

Forum|alt.badge.img+14
  • Honored Contributor
  • 351 replies
  • August 30, 2019

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


Forum|alt.badge.img+15
  • Esteemed Contributor
  • 719 replies
  • August 30, 2019

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.


Forum|alt.badge.img+31
  • Honored Contributor
  • 2721 replies
  • August 31, 2019

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.


Forum|alt.badge.img+31
  • Honored Contributor
  • 2721 replies
  • August 31, 2019

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


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings