PowerShell to Add user to two different groups RRS feed

  • Question

  • Hi There,

    I am trying to work out a way to place a user into two different security groups "Work" and "Projects" in one go. I have found examples of adding many users to a group with a .csv but this is not what i want to do, i have been on this for two days now and I need someone with much more experience then me to guide me though this issue. Below is a copy of the script I am playing with and you will see it doesn't work. 

    # adds the user to predefined group

    [int]$xMenuChoiceA = 0
    while ( $xMenuChoiceA -lt 1 -or $xMenuChoiceA -gt 4 ){
    Write-host "1. Normal User"
    Write-host "2. Manager"
    Write-Host "3. Work/Projects"
    Write-host "4. Quit and exit"
    [Int]$xMenuChoiceA = read-host "Please enter an option 1 to 4..." }
    Switch( $xMenuChoiceA ){
      # 1{Add-ADGroupMember -Identity "Domain Users" -Members $Sam}
      1{Write-host $Sam "has been added to Domain Users"}
      2{Add-ADGroupMember -Identity "Management" -Members $Sam}
      3{Add-ADGroupMember -Identity "Work, Projects" -Members $Sam}

    Could some please shed some light on a possible solution to this issue

    Thanks Nick  

    Nicholas Refalo

    Tuesday, May 10, 2016 8:51 AM


All replies