Problem in passing the directly variable to powershell command

Viewed 22

I am new to PowerShell scripting

I have scenario I need to set group names in ADServiceAccount, for that I have saved group names in one variable:

$groupnames = "grp1,grp2"
$accountname = "user1"
$controller = "DC=zzabc,DC=zzadc,dc=ap,dc=com"

I have tried with below command but with the below command it is through error

Set -ADSServiceAccount -Identity $accountname -groupnames $groupnames -server $controller

Error:

Identity info provided in the extended attribute : 'groupnames' could not b resolves, reason:'cannot find an object with identity:'grp1,grp2' under 'DC=zzabc,DC=zzadc,dc=ap,dc=com'

... but IF I pass directly group names to command it will work, like below

Set-ADSServiceAccount -Identity $accountname -groupnames grp1,grp2 -server $controller

Kindly help to resolve the issue,, Thanks in Advance!!!

1 Answers

The -groupnames parameter is expecting an array list of groups. Your $groupnames = "grp1,grp2" is creating a string, change it to create an array by doing this $groupnames = "grp1","grp2" and that should work for you

Related