Skip to content

Instantly share code, notes, and snippets.

@eliranmal
Created June 6, 2019 20:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eliranmal/e9be8fb5f0e1efd913620b9274ad1250 to your computer and use it in GitHub Desktop.
Save eliranmal/e9be8fb5f0e1efd913620b9274ad1250 to your computer and use it in GitHub Desktop.
changes the computer/host name in all relevant entries of the scutil
#!/usr/bin/env bash
function main() {
validate "$@"
set_name "$@"
if [[ "$2" == '-p' ]]; then
update_policy
fi
}
function validate() {
if [[ -z $1 ]]; then
usage
exit 1
fi
}
function set_name() {
local name="$1"
sudo scutil --set ComputerName "$name" && \
sudo scutil --set HostName "$name" && \
sudo scutil --set LocalHostName "$name" && \
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string "$name"
}
function update_policy() {
sudo jamf recon
sudo jamf policy
}
function usage() {
echo "
usage: ./compname.sh <name> [-p]
this command changes the computer/host name in all relevant entries of the scutil (ComputerName, HostName and LocalHostName).
pass a new name for the computer as the first argument. use the -p option to also update the jamf policy accordingly.
"
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment