unable to display variable data in text box

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.
User avatar
sivandavid
Posts: 9
Last visit: Sun Aug 01, 2021 11:48 pm

unable to display variable data in text box

Post by sivandavid »

hi
I created a new form
added a textbox to it and changed it to multiline and resized it to be big enough
then I changed it to read only and in the code all I put is this:

Code: Select all

$form1_Load={
	import-module activedirectory
	$user = "testuser"
	$UserData = Get-ADUser $user -Properties *
	$textbox2.Text = $UserData
}
when I run it after compiling it to exe all I get in the text box is:
CN=testuser,OU=contoso,DC=contoso,DC=local

I should see all the properties in $userdata but see only this line
what am I doing wrong ?

thanks in advance

jvierra
Posts: 14987
Last visit: Tue Nov 30, 2021 11:26 pm
Answers: 15
Has voted: 3 times
Been upvoted: 12 times

Re: unable to display variable data in text box

Post by jvierra »

If you return all properties the result will never fit in a textbox. "$userdata" is an object and not text. YOu must create and format text to add to you textbox.

Run the code at a command prompt and create teh correct output as text. You can use any formatter to crete teh text format you need.

User avatar
localpct
Posts: 353
Last visit: Tue Nov 23, 2021 11:27 am

Re: unable to display variable data in text box

Post by localpct »

No need to import the AD module
You should add a button to fire your get-aduser event
And as J said, you're trying to pull your entire AD into a single text box

User avatar
sivandavid
Posts: 9
Last visit: Sun Aug 01, 2021 11:48 pm

Re: unable to display variable data in text box

Post by sivandavid »

thank you for the quick response, was able to figure it out eventually
now I am facing a different issue, basically what I am doing is a form with a textbox on the top that I can type a username from AD and click load
on the left side it will show the current values of the user from AD and on the right side I need to enter new values and click save and it should save it to AD

but for some reason this code (which work in ISE) don't execute the command

Code: Select all

$office = $textbox25.Text

$params25 = @{
	Identity = $user
	Office = $office
}

$buttonSave_Click = {

	Set-ADUser @params25
	
}
any idea why ? it works in normal PS and in ISE
thanks for the help

User avatar
localpct
Posts: 353
Last visit: Tue Nov 23, 2021 11:27 am

Re: unable to display variable data in text box

Post by localpct »

New issue,
New thread

Also post the error PSS throws from the output tab

jvierra
Posts: 14987
Last visit: Tue Nov 30, 2021 11:26 pm
Answers: 15
Has voted: 3 times
Been upvoted: 12 times

Re: unable to display variable data in text box

Post by jvierra »

sivandavid wrote:
Fri Jul 30, 2021 12:39 pm
thank you for the quick response, was able to figure it out eventually
now I am facing a different issue, basically what I am doing is a form with a textbox on the top that I can type a username from AD and click load
on the left side it will show the current values of the user from AD and on the right side I need to enter new values and click save and it should save it to AD
You cannot click "load". YOu cannot automatically update AD with your code you have to write a whole form of code and design a method to take the form data and use a Set-AdUser to update the object.

I recommend using your search engine to learn about WinForms and the AD CmdLets.

Here are some videos and other resources to help get you started.

https://www.sapien.com/books_training/S ... d-Training

jvierra
Posts: 14987
Last visit: Tue Nov 30, 2021 11:26 pm
Answers: 15
Has voted: 3 times
Been upvoted: 12 times

Re: unable to display variable data in text box

Post by jvierra »

An addendum: You cannot edit text and turn into an array of parameters. Guessing will not work. You must first learn both PowerShell and WinForms as well as a deeper understanding of AD CmdLets.

You say the code works in ISE as you possted it but that is clearly impossible.

jvierra
Posts: 14987
Last visit: Tue Nov 30, 2021 11:26 pm
Answers: 15
Has voted: 3 times
Been upvoted: 12 times

Re: unable to display variable data in text box

Post by jvierra »

Here is a complete demo of how to update a user object with WinForms.
Attachments
Demo-ADUpdateForm.psf
(25.27 KiB) Downloaded 60 times

User avatar
sivandavid
Posts: 9
Last visit: Sun Aug 01, 2021 11:48 pm

Re: unable to display variable data in text box

Post by sivandavid »

sorry, I have the entire script working in CLI mode including interactive menus and all and I am trying to build it again in GUI form, I guess I should have upload an image to make it more clear, the load part is working without an issue and I created a different text box next to it for the update and I try to update it same way but it does not execute
I am unable to upload an image as I am new to this forum

thanks

User avatar
sivandavid
Posts: 9
Last visit: Sun Aug 01, 2021 11:48 pm

Re: unable to display variable data in text box

Post by sivandavid »

jvierra wrote:
Fri Jul 30, 2021 8:34 pm
Here is a complete demo of how to update a user object with WinForms.
thank you for going the extra mile to answer my question but I compiled this to EXE and tried it as well and it also don't save the entered fax number, I searched the entire ADSI object for this user and it didn't update

Locked