Skip to content

Instantly share code, notes, and snippets.

@talkingmoose
talkingmoose / Set Mobile Device Extension Attribute value.sh
Created February 17, 2022 18:01
Sample Jamf Pro API script to set the value of a mobile device extension attribute "Role" to a value of "Teacher".
#!/bin/bash
# server connection information
URL="https://talkingmoose.jamfcloud.com"
username="api-editor"
password="P@55w0rd"
# provide the Jamf Pro ID of the PreStage Enrollment; look in the URL when viewing the PreStage Enrollment
mobileDeviceID="15"
@talkingmoose
talkingmoose / Create User Account.zsh
Last active April 3, 2024 10:01
Simple script to create a new macOS user account. Will not provide a SecureToken.
#!/bin/zsh
# new user account details
username="lapsadmin"
displayName="LAPS Admin"
password="P@55w0rd"
admin="yes"
hidden="yes"
# determine next available UID
@talkingmoose
talkingmoose / Jamf Pro Provisioning 2.zsh
Created November 16, 2020 06:25
Runs when called by a Jamf Pro policy triggered by Enrollment Complete. Installs third party software that Apple's Volume Purchase Program (VPP) cannot install and runs maintenance routines (bind to Active Directory, set time zone etc.).
#!/bin/zsh
<<'ABOUT_THIS_SCRIPT'
-----------------------------------------------------------------------
Written by:William Smith
Professional Services Engineer
Jamf
bill@talkingmoose.net
@talkingmoose
talkingmoose / SearchLDAP Examples.sh
Created October 22, 2020 22:07
Syntax for looking up user information from a non-bound LDAP directory.
#!/bin/sh
# -H = LDAP URI
# -x = use simple authentication instead of SASL
# -b = search base
# -D = user principal name (UPN) of authenticating user
# -w = password of authenticating user
# look up a user's manager's distinguished name
@talkingmoose
talkingmoose / MegaPKGr.zsh
Last active June 26, 2023 05:37
The pkgbuild binary and Jamf Composer don't support adding single files of 8 GB or more to a package. Some apps like Install macOS Big Sur.app include files larger than 8 GB in their bundles. This script will create a deployable PKG file from apps whose bundles include those large files.
#!/bin/zsh
:<<ABOUT_THIS_SCRIPT
-------------------------------------------------------------------------------
Written by:William Smith
Professional Services Engineer
Jamf
bill@talkingmoose.net
https://gist.github.com/e9ed319226c6da30dd633725e48a97b0
@talkingmoose
talkingmoose / Hide Wi-Fi Menu.sh
Last active October 28, 2020 09:18
Quits the Wi-Fi menu item for the current user. Effectively unchecks the "Show Wi-Fi status in menu bar" item in System Preferences > Network.
#!/bin/zsh
# get current logged in user
currentUser=$( /usr/bin/stat -f "%Su" /dev/console )
echo "Current user is $currentUser"
# get current user home folder path
homeFolder=$( /usr/bin/dscl . read /Users/talkingmoose NFSHomeDirectory | /usr/bin/awk -F ": " '{ print $2 }' )
echo "Current user home folder is $homeFolder"
@talkingmoose
talkingmoose / Report admin status.bash
Created August 26, 2020 22:29
Report if any macOS user accounts with admin privileges exist.
#!/bin/bash
# list all users with UIDs above 501
usersList=$( /usr/bin/dscl . -list /Users uid | /usr/bin/awk '$2 >= 501 { print $1 }' )
# test for admin
while IFS= read aUser
do
/usr/sbin/dseditgroup -o checkmember -u "$aUser" admin 1>/dev/null
@talkingmoose
talkingmoose / Report unknown network services.zsh
Created August 3, 2020 03:19
Compares known and current network services and creates an unknown network services list.
#!/bin/zsh
# list of known network services that should be excluded from results
defaultNetworkServices="An asterisk (*) denotes that a network service is disabled.
USB-C Dock Ethernet
Apple USB Ethernet Adapter
Wi-Fi
iPhone USB
Bluetooth PAN
Thunderbolt Bridge"
@talkingmoose
talkingmoose / "Early Adopter" extension attribute
Last active November 21, 2023 22:31
Self Service policy to enable end users to enroll their Macs into an "Early Adopter Program" or any other type of enrollment. Create a Smart Computer Group to identify early adopters and scope policies.
#!/bin/zsh
enrollmentStatus=$( /usr/bin/defaults read '/Library/Preferences/EarlyAdopter.plist' Enrolled )
echo "<result>$enrollmentStatus</result>"
@talkingmoose
talkingmoose / Delete account from current user's Internet Accounts.sh
Last active June 21, 2023 19:24
Example for removing specific account from System Preferences > Internet Accounts for the current user.
#!/bin/bash
# get name of currently logged in user
currentUser=$( /usr/bin/stat -f "%Su" /dev/console )
echo "Current user is $currentUser."
# get current user's home folder
homeFolder=$( /usr/bin/dscl . read "/Users/$currentUser" NFSHomeDirectory | /usr/bin/awk -F ": " '{ print $2 }' )
# remove account by description name from Accounts sqlite database
/usr/bin/sqlite3 "$homeFolder/Library/Accounts/Accounts4.sqlite" 'DELETE FROM ZACCOUNT WHERE ZACCOUNTDESCRIPTION = "Exchange"'