Created
June 6, 2019 20:37
-
-
Save eliranmal/e9be8fb5f0e1efd913620b9274ad1250 to your computer and use it in GitHub Desktop.
changes the computer/host name in all relevant entries of the scutil
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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