Policy to enforce Computer Name

donmontalvo
Esteemed Contributor III

Is there a way to force the Computer Name using a reference list like a CSV?

We have a good number of Mac users who are grandfathered in with admin rights. That's not likely to change.

We're hoping to come up with a way to revert the Computer Name whenever a user changes it. Hoping after a few tries the user stops trying.

Possible with Casper?

Don

--
https://donmontalvo.com
7 REPLIES 7

lisacherie
Contributor II

I have achieved static computer names with the following:

Computer records created in OD for each computer
MCX to set computer name to computer record name
MCX to prevent changes to the sharing system preference pane

Can look up the MCX keys if you need them.

jafuller
Contributor

@lisacherie please share. :-)

carlo_anselmi
Contributor III

@lisacherie +1 for sharing, please!

I am currently linking OD computer records to static groups in JSS with LDAP "server connection" - used for Computer Lists but some of the hardware is not being shown in JSS (mainly newer models)
MAC address is not 100% reliable here...
Thank you!
Carlo

lisacherie
Contributor II

We are preventing changes to the computer name by using MCX. We are still on Open Directory MCX as we are very dependent on MCX and migrating all of the keys to Casper MCX is a big job that is still on my todo list.

This assumes the computer is bound to OD, you might also be able to achieve this by extending the AD schema - but not something I have tried.

1: Restrict access to the sharing pane in system preferences
2: Force computer name to use OD computer record name

Part 1:
com.apple.systempreferences
-> EnabledPreferencesPanes-Raw array
// contains string objects for each preference that is allowed eg.
name 0 type string value com.apple.preference.displays
name 1 type string value com.apple.preference.sound
etc....

Part 2:
com.apple.loginwindow
name UseComputerNameForComputerRecordName type boolean value true

Hope this helps.

Lisa.

lisacherie
Contributor II

Because adding lots of computers to OD is a pain (we are over 1500), here is a script you can use to bulk import from a spreadsheet.

#!/usr/bin/env ruby

odAdmin="your directory admin shortname" #enter your OD admin name between the quotes
odPassword="the password"  # Enter your OD admin password between the quotes
domain="odserver.yourdomain.com" # FQDN of your OD domain

filename = "your csv file.csv"

file = File.new(filename, 'r')

# column numbering begins at 0, [ indicates end of row in the csv file

file.each_line("[") do |row|
  columns = row.split(",")
  computer_long_name = columns[2]
  computer_short_name = columns[3] 
  mac_address = columns[1]

  puts "#{computer_long_name}, #{computer_short_name}, #{mac_address}, #{computer_list}
"

  # Add computer to to OD
  puts "The comand to add the computer would be (commented out command directly below):
"
  puts "dscl -u #{odAdmin} -P #{odPassword} /LDAPv3/#{domain} -create /Computers/#{computer_short_name} ENetAddress #{mac_address}
"
       `dscl -u #{odAdmin} -P #{odPassword} /LDAPv3/#{domain} -create /Computers/#{computer_short_name} ENetAddress #{mac_address}`

  # Set the real name of the computer
  puts "

The comand to set the real name would be (commented out command directly below):
"
  puts "dscl -u #{odAdmin} -P #{odPassword} /LDAPv3/#{domain} -merge /Computers/#{computer_short_name} RealName "#{computer_long_name}"
"
       `dscl -u #{odAdmin} -P #{odPassword} /LDAPv3/#{domain} -merge /Computers/#{computer_short_name} RealName "#{computer_long_name}"`    

end

tlarkin
Honored Contributor

This solution only works if you are using Open Directory though, correct?

lisacherie
Contributor II

The MCX to set the host name is in MCX template provided in the JSS so I'm hoping it still works with Casper MCX assuming the computer record is defined in the directory - Something to test...

I also hope that if AD was extended for the computer records the MCX from the JSS would work too.