Assigning Department During Imaging?

Jalves
Contributor

Hey guys, I'm looking to have my department, maybe even building set automatically during imaging. I have 3 department groups; staff, admin, and student. We are using and AD right now, but until we re-organize it, I cannot rely on it to pull department info correctly. I was wondering if anyone knew how to script this out? I'm not sure if the API is needed. Thank You!

8 REPLIES 8

Lhsachs
Contributor II

I have a set of scripts I use to set departments (one script per department):

#!/bin/sh

#SetDepartmentFieldinCasper#

#SetDeptasVariable#
vdept="Your_dept"

#set the dept in Casper#
jamf recon -skipApps -skipFonts -skipPlugins -department $vdept

bentoms
Release Candidate Programs Tester

@Lhsachs are you sure that those recon verbs still work?

I ask because of this FR

Jalves
Contributor

Hey @Lhsachs, I just tried out that script and I wasn't able to populate any Department settings. I'm not sure if it's related to @bentoms post. Have you been imaging with those recently? I know an alternative way, is using prestage images, but I have a feeling we may miss updating those manually when machines change hands or switch departments. Thank You!

Lhsachs
Contributor II

I ran the script today to test... and it worked fine... The scripts are normally used by groups I don't control - who image their own macs... and filling in the department helps us with asset management.

The department names they fill with are already choices for the department field

Jalves
Contributor

It's working perfectly thank you. I just realized I had a space in my department name and I wasn't entering that correctly into the script. Thanks Again for the help!

ggigliotti
New Contributor II

Is this still working for you? I'm running JSS 9.91 and i'm currently having a problem with running the script during imaging. Everything installs fine on the image but it never runs the script to change the department. I have a policy set up so I can call the script in self service and when I do that it works just fine. No other scripts are set up to run during imaging and I have the priority set to After.

Jalves
Contributor

I just took another look back into this. I haven't needed that script to actually work for a while during imaging, but it looks like its not working now. Ive tried the script at reboot, in a payload free pkg to install on reboot, and even a script running at reboot that just triggers a policy containing that script or pkg and nothing is working in an automated way. I can run the commands manually or via self service and they still work that way.

Discher
New Contributor III

Hello everyone!

Dusting off a 6 year old thread here.  I also wanted to script an input prompt for Computer Name, and Department after the Prestage Enrollment, so I could have it in Self-Service for my student techs.

The recon switches work great.

I had a few failures because of spaces in my Department names, but if you "double quote" the variable input, spaces in a Department name are fine.  Here is the script I have setup in Self-Service.  Thanks everyone!

 

#!/bin/bash

#Input Prompt for Computer Name
computername=$(/usr/bin/osascript<<END
tell application "System Events"
activate
set the answer to text returned of (display dialog "Please enter the computer name :" 
default answer "" buttons {"Rename"} default button "Rename")
end tell
END)

#Input Prompt for Department
dept=$(/usr/bin/osascript<<END
tell application "System Events"
activate
set the answer to text returned of (display dialog "Please enter the dept name :"
default answer "" buttons {"Rename"} default button "Rename")
end tell
END)

echo $computername
jamf setcomputername -name $computername

echo "$dept"
jamf recon -department "$dept"