Hello,<\/p>\n
I see a few scripts to add a user to multiple groups but i don’t see how it can mesh with my current code i made.<\/p>\n
If someone could help steer me in the right direction i would be grateful.<\/p>\n
My Code example:<\/p>\n
$officegroup = “Accounting Department” + “Home Office” + “Corporate”<\/p>\n
New-ADUser -SamAccountName $adusername -GivenName $firstname -Surname $lastname -office “$office” -Manager $usermgr -DisplayName “$firstname $lastname” -Name “$firstname $lastname” -UserPrincipalName $UserPrincipalName -Enabled $true -ChangePasswordAtLogon $true<\/p>\n
Add-ADGroupMember -Identity $officegroup -Members $adusername<\/p>\n
Add-ADGroupMember is not taking the grouping i have above this example for some reason.<\/p>\n
It does work if $officegroup is only one item fine just not more then one <\/p>","upvoteCount":6,"answerCount":7,"datePublished":"2019-02-26T19:33:28.000Z","author":{"@type":"Person","name":"stephenmifsud","url":"https://community.spiceworks.com/u/stephenmifsud"},"acceptedAnswer":{"@type":"Answer","text":"
summat like so<\/p>\n
$officegroup = \"Accounting Department\",\"Home Office\",\"Corporate\"\n\n$ADUserInfo = @{\n SamAccountName = $adusername \n GivenName = $firstname \n Surname = $lastname \n Office = \"$office\" \n Manager = $usermgr \n DisplayName = \"$firstname $lastname\" \n Name = \"$firstname $lastname\" \n UserPrincipalName = $UserPrincipalName \n Enabled = $true \n ChangePasswordAtLogon = $true\n}\nNew-ADUser @ADUserInfo\n\nforeach($group in $officegroup){\n Add-ADGroupMember -Identity $group -Members $adusername\n}\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2019-02-26T20:08:51.000Z","url":"https://community.spiceworks.com/t/powershell-adding-a-single-user-to-multiple-groups/699519/6","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},"suggestedAnswer":[{"@type":"Answer","text":"Hello,<\/p>\n
I see a few scripts to add a user to multiple groups but i don’t see how it can mesh with my current code i made.<\/p>\n
If someone could help steer me in the right direction i would be grateful.<\/p>\n
My Code example:<\/p>\n
$officegroup = “Accounting Department” + “Home Office” + “Corporate”<\/p>\n
New-ADUser -SamAccountName $adusername -GivenName $firstname -Surname $lastname -office “$office” -Manager $usermgr -DisplayName “$firstname $lastname” -Name “$firstname $lastname” -UserPrincipalName $UserPrincipalName -Enabled $true -ChangePasswordAtLogon $true<\/p>\n
Add-ADGroupMember -Identity $officegroup -Members $adusername<\/p>\n
Add-ADGroupMember is not taking the grouping i have above this example for some reason.<\/p>\n
It does work if $officegroup is only one item fine just not more then one
<\/p>","upvoteCount":6,"datePublished":"2019-02-26T19:33:28.000Z","url":"https://community.spiceworks.com/t/powershell-adding-a-single-user-to-multiple-groups/699519/1","author":{"@type":"Person","name":"stephenmifsud","url":"https://community.spiceworks.com/u/stephenmifsud"}},{"@type":"Answer","text":"
If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n