Skip to content

Instantly share code, notes, and snippets.

@talkingmoose
talkingmoose / Last Reboot.zsh
Last active December 20, 2024 00:53
Jamf Pro extension attribute to return date of last reboot. Create the EA with a Data Type of 'date'. This allows a Smart Group to use greater than and less than calculations.
#!/bin/zsh
# get last reboot date and time
lastReboot=$( /usr/bin/last -y reboot )
# extract date and time (e.g. Thu Dec 12 2024 08:35)
rebootTime=$( /usr/bin/awk -F '[[:space:]]{3,}' 'NR==1 { print $2 }' <<< "$lastReboot" )
# convert date and time to ISO date format
lastRebootISO=$( /bin/date -j -f "%a %b %e %Y %H:%M" "$rebootTime" '+%Y-%m-%d %I:%M:00' )
@talkingmoose
talkingmoose / Existing user accounts.zsh
Last active September 15, 2024 18:42
A Jamf Pro extension attribute to return whether a user account (hidden or visible) in a list of user accounts exists on a computer.
#!/bin/zsh
:<<ABOUT_THIS_EXTENSION_ATTRIBUTE
-----------------------------------------------------------------------
Written by:William Smith
Technical Enablement Manager
Jamf
bill@talkingmoose.net
https://gist.github.com/talkingmoose/4a2b613bf5273081459bc62c644193eb
@talkingmoose
talkingmoose / Back up Jamf Pro objects.zsh
Last active January 2, 2025 14:50
Download JSON or XML files for multiple Jamf Pro object types.
#!/bin/zsh
# set -x # show command
:<<ABOUT_THIS_SCRIPT
Written by:William Smith
Technical Enablement Manager
Jamf
bill@talkingmoose.net
https://gist.github.com/talkingmoose/4a950a715ad07ae3baecce2f46b0a7e5

AWK • SED • GREP: Together we can change anything!

Download a PDF of my slides and notes

awk sed grep circle logo

Example code from my MacAdmins Conference at Penn State 2024 presentation.

Battery cycle count

Jamf Pro LAPS scripts

Example scripts for managing, administerting, and auditing Jamf Pro LAPS accounts.

Use these as models for creating scripts for your own workflows.

  • Get Jamf Pro LAPS Settings.zsh
  • Configure Jamf Pro LAPS Settings.zsh
  • Get Jamf Pro LAPS Account Information.zsh
  • Get Jamf Pro LAPS Account Password.zsh
@talkingmoose
talkingmoose / Download device model information from Jamf.zsh
Last active June 19, 2024 15:47
Apple doesn't provide a 1:1 list of devices for iOS, iPadOS, tvOS, watchOS, and visionOS. However, Jamf does maintain a public list for its Jamf Pro servers. This script downloads the listm parses the information, and creates a record of each device followed by its display name.
#!/bin/zsh
# set -x # show command
# trap read debug # require a RETURN after each command
# download mobile device data from Jamf
xml=$( /usr/bin/curl \
--silent \
--url https://hw-model-names.services.jamfcloud.com/1/mobileDeviceModels.xml )
@talkingmoose
talkingmoose / iOS and iPadOS 18 and watchOS 11 compatible devices (regex)
Last active January 17, 2025 15:43
Regex looks for all iPhone and iPad models compatible with iOS or iPadOS 18 and Apple Watch models compabiel with watchOS 11. May not be up-to-date with newly released models.
https://support.apple.com/guide/iphone/iphone-models-compatible-with-ios-18-iphe3fa5df43/ios
https://support.apple.com/guide/ipad/ipad-models-compatible-with-ipados-18-ipad213a25b2/ipados
https://www.apple.com/watchos/watchos-11/
Published Date: June 10, 2024
Updated November 1, 2024
Verification: https://regex101.com/r/0UDJHk/7
1) Exact regex — Matches major model identifier numbers based on Jamf's hardware model identifiers list (more accurate):
@talkingmoose
talkingmoose / Sequoia-compatible Macs (regex)
Last active December 13, 2024 21:13
Regex looks for all Mac models compatible with macOS Sequoia. May not be up-to-date with newly released models.
https://www.apple.com/macos/macos-sequoia/
Published Date: June 10, 2024
Updated November 8, 2024
Verification: https://regex101.com/r/bNOMXz/9
1) Exact regex — Matches major model identifier numbers based on Apple's knowledge base article (more accurate):
^(Mac(1[3-6]|BookPro1[5-8]|BookAir(9|10)|Pro7)|iMac(Pro1|(19|2[01]))|Macmini[89]),\d+$
@talkingmoose
talkingmoose / Re-enroll computers for LAPS.zsh
Last active December 3, 2024 18:41
Use a Jamf Pro policy to re-enroll a computer to install a LAPS management account, and then create a launch daemon and script to update inventory immediately.
#!/bin/zsh
:<<ABOUT_THIS_SCRIPT
-------------------------------------------------------------------------------
Written by:William Smith
Technical Enablement Manager
Jamf
bill@talkingmoose.net
https://gist.github.com/talkingmoose/9f4638932df28c4bebde5dd47be1812a
@talkingmoose
talkingmoose / Location Information.zsh
Created April 9, 2024 16:50
Add the following script to a Jamf Pro extension attribute to collect service provider location information based on public IP address when updating inventory.
#!/bin/zsh
# get public IP address
publicIP=$( /usr/bin/curl http://ifconfig.me/ip \
--location \
--silent \
--max-time 10 )
# get GeoIP data
locationData=$( /usr/bin/curl http://ip-api.com/xml/$publicIP \