adding data to department field

Welcome Forums General PowerShell Q&A adding data to department field

Viewing 0 reply threads
  • Author
    Posts
    • #6179
      Member
      Topics: 1562
      Replies: 0
      Points: 0
      Rank: Member

      by lanman_4 at 2012-09-17 09:51:16

      Hi,
      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 (schoolname_students) and then add the data to all users in these groups or ...??

      thx in advance for help with this,
      l

      by RichLec at 2012-09-17 11:38:35

      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.html

      $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

      by RichardSiddaway at 2012-09-17 13:19:25

      If you have a group then it becomes this
      Get-ADGroupMember -Identity Legal |
      where {$_.objectclass -eq "user"} |
      foreach {
      Set-ADUser -Identity $($_.distinguishedName) -Department "Student"
      }

      you can test the result like this

      Get-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

      by lanman_4 at 2012-09-18 08:51:31

      Hi Richard,
      Thanks for the script,, it worked perfectly

      l

      by RichardSiddaway at 2012-09-18 09:52:26

      You're very welcome

Viewing 0 reply threads
  • The topic ‘adding data to department field’ is closed to new replies.