Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Declare Variables
- # This is the name of the Jamf Pro Account that has priviges for the API. Note this should be limited
- apiuser=""
- # This is the password of the Jamf Pro Account that has priviges for the API. Note this should be limited
- apipass=""
- # This is the Jamf Pro URL
- jamfurl=""
- # This will set a default Prefix for a computer name
- prefix="EDU"
- # hardcode Serial Number Variable
- serialNumber=""
- # Get Serial Number
- serialNumber="$(system_profiler SPHardwareDataType | awk '/Serial Number/{print $4}')"
- # Get the Current Assigned User
- User=$(curl -su "$apiuser":"$apipass" -H "Accept: application/xml" "$jamfurl"JSSResource/computers/serialnumber/"$serialNumber" | xmllint --xpath '/computer/location/username/text()' -)
- # Get assigned Building
- Building=$(curl -su "$apiuser":"$apipass" -H "Accept: application/xml" "$jamfurl"JSSResource/computers/serialnumber/"$serialNumber" | xmllint --xpath '/computer/location/building/text()' -)
- # Check to see if a user is assigned, if not, exit script using error code 1
- if [[ "$User" == "" ]]; then
- echo "User not assigned to computer record"
- exit 1
- fi
- # Check to see if a building is assigned, if not, exit script using error code 2
- if [[ "$Building" == "" ]]; then
- echo "Building not assigned to computer record"
- exit 2
- fi
- # Set Variable for naming computer
- computerName=$(echo "$prefix-$Building-$User")
- # Set Computer Name
- sudo scutil --set HostName "$computerName"
- sudo scutil --set LocalHostName "$computerName"
- sudo scutil --set ComputerName "$computerName"
- echo "$computerName"
Add Comment
Please, Sign In to add comment