Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem in passing the directly variable to powershell command

Tags:

powershell

set

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

like image 223
Lakshmi Avatar asked Aug 12 '26 14:08

Lakshmi


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

like image 191
Jonathan Waring Avatar answered Aug 14 '26 12:08

Jonathan Waring



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!