I am having problems trying to display data in a listbox (data populates in the richtextbox correctly). This is the code I am using, I am sure its an easy fix, thanks in advance :
$roles = Get-ADDomain -Server dc2 | select InfrastructureMaster, PDCEmulator, RIDMaster | Out-String
$listbox1.Items.Add($roles)
$richtextbox1.Text = $roles
Output data to listbox
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.
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.
Re: Output data to listbox
Nothing in particular just testing to see how and what types of data can be output to to different objects. Learning...
Re: Output data to listbox
So for example if I am building an AD tool with multiple functions like listing all expired AD accounts and am using the listbox to display the results I should be able to or would like to be able to display the results of other queries like the one in question in the same listbox or would i need to utilize a RichTextBox for that?
Re: Output data to listbox
You will never successfully guess you way through both PowerShell and Windows Forms. It requires concentrated study.
Start by reading the blog posts on forms:
http://www.sapien.com/blog/topics/user- ... istrators/
There are numerous other sets of blog posts on controls and design.
Start by reading the blog posts on forms:
http://www.sapien.com/blog/topics/user- ... istrators/
There are numerous other sets of blog posts on controls and design.
Re: Output data to listbox
I appreciate your feedback but thats a little presumptuous that I am just guessing my way through PS. Actually I have read many tuorials and have learned alot. I have searched for an answer before asking the question since I was unable to find the answer I figured I would ask here. A better response would have been that it can not or should not be done this way and than show the correct way. Was just curious if it could be done.
Thanks
Thanks
Re: Output data to listbox
No - you have not read about how to use Windows Controls. If you had you would know that a listbox is a collection of objects saved as items in a list control. You would also know that your AD query does not return a list but a single object that cannot be displayed as list.
I highly recommend reading the posts on how to use Forms to design Admin forms. It is exactly what you are asking to know. I cannot explain it any better than the blog post and the blog post has many examples of how to code it.
The simple answer to your question is that you can add any collection of objects that support the IList interface to a listbox. In PowerShell Studio this loosely equates to anything that can be produces as a dataset or as an System.Collections.Arraylist.
You can also just add strings one at a time.
I highly recommend reading the posts on how to use Forms to design Admin forms. It is exactly what you are asking to know. I cannot explain it any better than the blog post and the blog post has many examples of how to code it.
The simple answer to your question is that you can add any collection of objects that support the IList interface to a listbox. In PowerShell Studio this loosely equates to anything that can be produces as a dataset or as an System.Collections.Arraylist.
You can also just add strings one at a time.
PowerShell Code
Double-click the code block to select all.$listbox1.Items.Add('some string') $files=dir $env:userprofile\Documents -file $listbox1.Items.AddRange([System.Collections.Arraylist]$files)Not having any idea what you are trying to do makes it nearly impossible to know what to show you. Please do the blog posts until you understand what the issues are.
Re: Output data to listbox
Whatever jvierra, if i read everything and knew everything i wouldn't have to ask questions. Its responses like yours that turn new users off. I'm glad I don't react that way when someone asks about VMWare, I try to spread the knowledge that I have in my field of expertise. In my way of thinking there is no stupid question if you are trying to learn, obviously you don't see it the same way. Like I said I have gone through many tuts but haven't done it all. Life is about questions and if you stop asking questions your not learning. Thanks Again. No hard feelings, I will keep reading , learning and asking questions.