Script to write computer hostnames to Static Computer Group.

Naren
New Contributor III

Dear Masters!!

Hoping this would be the great place of masters who can really help me with script or solution.

I had a requirement to write computer Hostnames to JSS Static Computer Group.

I would receive consolidated .xml or .csv file for admin rights from support groups.

Now, I need a script to read computer objects from that .XML or .CSV file lookup for JSS inventory if computer hostname is available then that computer Hostname needs to be added to Static computer Group. Before adding new computer hostnames script should fist remove all existing computers from that group and then add new entries to it.

Looking forward for responses on this post! Thank you!

1 ACCEPTED SOLUTION

sdagley
Esteemed Contributor II

@Naren You can't explicitly add a Mac to a Smart Group, the criteria of a Smart Group determine what the membership is. That said, you could use a Static Group and add a Mac to it via a script, or set an Extension Attribute via a script and what you write to the EA could trigger membership in a Smart Group.

You can definitely automate the process you describe, but you're not likely to find something pre-written and available on Jamf Nation. You will find scripts you can use as building blocks however.

View solution in original post

5 REPLIES 5

sdagley
Esteemed Contributor II

@Naren Unless you must have a script this tool will make your life much easier if you're looking to make bulk changes to Static Groups: MUT (or its simplified version: MUT Classic)

Naren
New Contributor III

@sdagley Thank you for sharing that info. Cheers!!

Naren
New Contributor III

@sdagley My JSS Instance is hosted on Windows server, I am actually looking to automate admin rights exceptions.

We have internal portal where users log for admin rights request once it completes approval process approved users and computer list will be shared in xml or csv file for us everyday.
Now, here I would like to automate this as we get xml/.csv file to share folder, I need as script to read this file and lookup for existing hostnames in jss database. If hostname is matching in jss db then script need to add computers to smartcomputer group OR extension attributes as Admin Exception Device.

As we get everyday new list., old devices should be removed and new devices shall be added.

Not sure, if this is practically possible.. just looking for script to help in this community. :)

  • Naren

sdagley
Esteemed Contributor II

@Naren You can't explicitly add a Mac to a Smart Group, the criteria of a Smart Group determine what the membership is. That said, you could use a Static Group and add a Mac to it via a script, or set an Extension Attribute via a script and what you write to the EA could trigger membership in a Smart Group.

You can definitely automate the process you describe, but you're not likely to find something pre-written and available on Jamf Nation. You will find scripts you can use as building blocks however.

Look
Valued Contributor III

I would do as @sdagley suggested with an EA.
Rather than having a static group that you try and manage directly, have a manually populated EA on each device and then use the criteria in that to populate a smart group.
Then have a script that checks each computer against the list and sets it's EA accordingly, that way the adds and removes would all happen easily within the same script as single actions on individual computers.