by lanman_4 at 2012-09-17 09:51:16
Hi,by RichLec at 2012-09-17 11:38:35
I need to add data (student) to the department field on selected user accounts (only student accounts).
Can I do this using a script that will identify the student group (schoolnamestudents) and then add the data to all users in these groups or …??
thx in advance for help with this,
l
I would think you can use set-aduser from the activedirectory module to set this. You may need to use get-aduser to populate a list and then run that through a for-each block. I had to do something like this recently where i had a attribute in AD for password not required set incorrectly on a whole bunch of old users. The code below is what I used to make this change on all my users. This code might be able to be adjusted and tweaked to work for you particuler issue. I do have a blog post for this script. http://justawinadmin.blogspot.com/2012/ … ibute.htmlby RichardSiddaway at 2012-09-17 13:19:25$users = Get-Content "C:\lists\userlist.txt"
foreach ($user in $users){
$Cmd = get-aduser -identity $user
$Cmd.PasswordNotRequired = "FALSE"
Set-ADUser -Instance $Cmd}
In the userlist.txt the format is:
User1
User2
User3
-Rich
If you have a group then it becomes thisby lanman_4 at 2012-09-18 08:51:31Get-ADGroupMember -Identity Legal |
where {$.objectclass -eq "user"} |
foreach {
Set-ADUser -Identity $($.distinguishedName) -Department "Student"
}
you can test the result like thisGet-ADGroupMember -Identity Legal |
where {$.objectclass -eq "user"} |
foreach {
Get-ADUser -Identity $($.distinguishedName) -Property Department |
select Name, distinguishedName, Department
}
the where {$.objectclass -eq "user"} filters out nested groups
Hi Richard,by RichardSiddaway at 2012-09-18 09:52:26
Thanks for the script, it worked perfectly
l
You’re very welcome