extsupport
asked on
Powershell: Adding users to a group by job title
I have this syntax so far. What I am looking to do is, add a user to group by job title
add user to distribution group .RBCO04_Management from OU RBC04 with a title "RBCO MANAGER"
Import-module activedirectory
$Group = ".RBCO04_Management"
$Search = Get-ADOrganizationalUnit -Filter 'name -like "RBCO4"'
ForEach ($OU in $Search)
{
$OU.DistinguishedName
$User = Get-ADUser -Filter -properties Title -SearchBase "RBCO MANAGER" $OU.DistinguishedName
$User.sAMAccountName
$User | Foreach { Add-ADGroupMember -Identity $Group -Members $User.sAMAccountName -ErrorAction SilentlyContinue -Confirm:$false }
add user to distribution group .RBCO04_Management from OU RBC04 with a title "RBCO MANAGER"
Import-module activedirectory
$Group = ".RBCO04_Management"
$Search = Get-ADOrganizationalUnit -Filter 'name -like "RBCO4"'
ForEach ($OU in $Search)
{
$OU.DistinguishedName
$User = Get-ADUser -Filter -properties Title -SearchBase "RBCO MANAGER" $OU.DistinguishedName
$User.sAMAccountName
$User | Foreach { Add-ADGroupMember -Identity $Group -Members $User.sAMAccountName -ErrorAction SilentlyContinue -Confirm:$false }
ASKER
Get-ADUser : A positional parameter cannot be found that accepts argument 'OU=RBCO4,OU=FL,OU=Field Centers,DC=Lincare,DC=com' .
At H:\Projects\InquisiqR4\Bil ling portal\add_inquisiq_Superv isor.ps1:8 char:10
+ $User = Get-ADUser -Filter {title -like $pattern} -properties Title -SearchBase ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ADUser], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFoun d,Microsof t.ActiveDi rectory.Ma nagement.C ommands.Ge tADUser
Add-ADGroupMember : Cannot validate argument on parameter 'Members'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At H:\Projects\InquisiqR4\Bil ling portal\add_inquisiq_Superv isor.ps1:1 0 char:64
+ $User | Foreach { Add-ADGroupMember -Identity $Group -Members $User.sAMAccountN ...
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Add-ADGroupMember], ParameterBindingValidation Exception
+ FullyQualifiedErrorId : ParameterArgumentValidatio nError,Mic rosoft.Act iveDirecto ry.Managem ent.Comman ds.AddADGr oupMember
At H:\Projects\InquisiqR4\Bil
+ $User = Get-ADUser -Filter {title -like $pattern} -properties Title -SearchBase ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ADUser], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFoun
Add-ADGroupMember : Cannot validate argument on parameter 'Members'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
At H:\Projects\InquisiqR4\Bil
+ $User | Foreach { Add-ADGroupMember -Identity $Group -Members $User.sAMAccountN ...
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Add-ADGroupMember], ParameterBindingValidation
+ FullyQualifiedErrorId : ParameterArgumentValidatio
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window