Cannot add-groupmember in PS Studio with variable

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Cannot add-groupmember in PS Studio with variable

Post by stevens »

Hi,

When executing:

Add-ADGroupMember -Identity $textbox2.text -Members $ADObjectsToAdd

I get the following message:
>> Add-ADGroupMember -Identity testgroup -Members $ADObjectsToAdd
Cannot find an object with identity: 'test01, test02' under: 'DC=subdomain,DC=domain,DC=local'.

However, when I execute the command while debugging it works fine:
Add-ADGroupMember -Identity testgroup -Members user1,user2

$ADObjectsToAdd contains
user1,user2

$ADOBjectsToAdd.count shows only 1 item
$ADobjectsToAdd | gm shows system.string

Please advise howto debug.
J.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Cannot add-groupmember in PS Studio with variable

Post by jvierra »

Use an array and not a string.
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Cannot add-groupmember in PS Studio with variable

Post by stevens »

That's exactly what I'm trying but I can't make it into one.

Tried
$ADObjectsToAdd = @()
$ADObjectsToAdd = $AddEmployeeForm_textboxnames

tried
[array]$ADObjectsToAdd += $AddEmployeeForm_textboxnames

but did not work
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Cannot add-groupmember in PS Studio with variable

Post by jvierra »

You cannot cast a string to an array. If you use a multiline textbox the "Lines" property will be an array.
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Cannot add-groupmember in PS Studio with variable

Post by stevens »

Nice, that works indeed for a textbox multilined!
However, I need to have the values of a multilined textbox in a external form. That would be $EntriesIWantToGet = $AddEmployeeForm_textboxnames
There is no property lines for $AddEmployeeForm_textboxnames ... :-(
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Cannot add-groupmember in PS Studio with variable

Post by jvierra »

No idea what any of that means. You cannot retrieve anything from a child form if you didn't create it from scratch your self.
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Cannot add-groupmember in PS Studio with variable

Post by stevens »

Ok, I understand. Here an example of what I'm trying to do (att.).
Attachments
ADDADObjects.zip
(277.13 KiB) Downloaded 102 times
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Cannot add-groupmember in PS Studio with variable

Post by stevens »

It does work with single line indeed.
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Cannot add-groupmember in PS Studio with variable

Post by stevens »

Hi,

Could you advise on howto get multilined variable back from another form?
My example shows it is working for single line textbox but not for a multilined textbox.
The variable in the other form does not have a property lines either.

Thanks for your feedback.
J.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Cannot add-groupmember in PS Studio with variable

Post by jvierra »

You cannot pass a variable from a modal form to the parent. Use a global.
This topic is 6 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked