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.
User avatar
stevens
Posts: 273
Joined: Wed Jun 15, 2016 2:26 am

Cannot add-groupmember in PS Studio with variable

Post by stevens » Wed Sep 13, 2017 8:54 am

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.

User avatar
jvierra
Posts: 11242
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Cannot add-groupmember in PS Studio with variable

Post by jvierra » Wed Sep 13, 2017 10:39 am

Use an array and not a string.

User avatar
stevens
Posts: 273
Joined: Wed Jun 15, 2016 2:26 am

Re: Cannot add-groupmember in PS Studio with variable

Post by stevens » Wed Sep 13, 2017 12:03 pm

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

User avatar
jvierra
Posts: 11242
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Cannot add-groupmember in PS Studio with variable

Post by jvierra » Wed Sep 13, 2017 12:27 pm

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: 273
Joined: Wed Jun 15, 2016 2:26 am

Re: Cannot add-groupmember in PS Studio with variable

Post by stevens » Thu Sep 14, 2017 12:32 am

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 ... :-(

User avatar
jvierra
Posts: 11242
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Cannot add-groupmember in PS Studio with variable

Post by jvierra » Thu Sep 14, 2017 12:38 am

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: 273
Joined: Wed Jun 15, 2016 2:26 am

Re: Cannot add-groupmember in PS Studio with variable

Post by stevens » Thu Sep 14, 2017 1:06 am

Ok, I understand. Here an example of what I'm trying to do (att.).
Attachments
ADDADObjects.zip
(277.13 KiB) Downloaded 2 times

User avatar
stevens
Posts: 273
Joined: Wed Jun 15, 2016 2:26 am

Re: Cannot add-groupmember in PS Studio with variable

Post by stevens » Thu Sep 14, 2017 2:24 am

It does work with single line indeed.

User avatar
stevens
Posts: 273
Joined: Wed Jun 15, 2016 2:26 am

Re: Cannot add-groupmember in PS Studio with variable

Post by stevens » Fri Sep 15, 2017 5:31 am

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.

User avatar
jvierra
Posts: 11242
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Cannot add-groupmember in PS Studio with variable

Post by jvierra » Fri Sep 15, 2017 5:38 am

You cannot pass a variable from a modal form to the parent. Use a global.

Post Reply