For those of you who may be looking to answer the same question, here's how I got it to work in my case (I'm working on a Drupal 8.3 site):
$users = [ 'test_local_contributor' => [ 'password' => '1testme1', 'langcode' => $language, 'preferred_langcode' => $language, 'email' => '[email protected]', 'roles' => [ 'employee', 'local_contributor', 'testuser', ], 'location' => [ 'Kentucky', 'Paradise', ], 'sbu' => 'energy', 'bu' => 'natural_gas', ], ...(there were other test users, omitted for brevity) ]; foreach ($users as $key => $user) { $newUser = User::create(); $newUser->setUsername($key); $newUser->setPassword($user['password']); $newUser->enforceIsNew(); $newUser->setEmail($user['email']); $newUser->set('langcode', $user['langcode']); $newUser->set('preferred_langcode', $user['langcode']); foreach ($user['roles'] as $role) { $newUser->addRole($role); } $newUser->set('status', 1); if (isset($user['bu'])) { $term = \Drupal::entityTypeManager() ->getStorage('taxonomy_term') ->loadByProperties(['name' => $user['bu'], 'vid' => 'tx_business_unit']); $keys = array_keys($term); $newUser->set('user_bu', $keys); } if (isset($user['sbu'])) { $term = \Drupal::entityTypeManager() ->getStorage('taxonomy_term') ->loadByProperties(['name' => $user['sbu'], 'vid' => 'tx_sbu']); $keys = array_keys($term); $newUser->set('user_sbu', $keys); } $loc_keys = array(); foreach ($user['location'] as $location) { $newkeys = array(); $term = \Drupal::entityTypeManager() ->getStorage('taxonomy_term') ->loadByProperties(['name' => $location, 'vid' => 'tx_user_location']); $keys = array_keys($term); $newkeys = array_merge($loc_keys, $keys); $loc_keys = $newkeys; } $newUser->set('user_location', $loc_keys); $result = $newUser->save(); }