this works great if all the records are for the same UserID. However, the csv that I am given has multiple user accounts. In other words the first 10 records will be for userA with a unique logonrestriction value (10 unique computer names). The next 20 records will be for user B with an entirely different list of computer names. I have like 27 unique user IDs and the total record count is 1800.
Is there a clever way to built the $comparray for the first unique user ID then run the set-aduser command and then build the $comparray for the next unique user ID and so on and so on?
Dave - this is exactly what I needed. Excellent! One more question, is it possible to do group-object nesting?
The object of the scrip is to do the following…
for each unique user:
Add the machines listed in the LogonRestrictions column to the LogonRestrictions attribute
Add the user account to the groups listed in the GroupName column.
Note: the GroupName might have the group name value repeated (same value) or it could be a different value. So I guess I would use the group-object to pull the unique values from the GroupName column.
You can have nested loops and nested calls to Group-Object if you like, but what you’re describing doesn’t sound like you need a second call to Group-Object. Instead, for each user, you just want to create a list of unique computer names and group names (which can be done with Select-Object, rather than Group-Object). For example: