Product, version and build: 5.5.149
32 or 64 bit version of product: 64
Operating system: Windows 10 & 7
32 or 64 bit OS: Both
Hi. The following code works. It reads the local administrators group and then displays the groups in the RichText field. My issue is it displays the groups like this:
Group1 Group2 Group3. How do I make it display like this?
Group1
Group2
Group3
$buttonShowLocalAdmin_Click = {
$Computer1 = $PCNameBox.Text
$ADSIComputer = [ADSI]("WinNT://$Computer1,computer")
$group = $ADSIComputer.psbase.children.find('Administrators', 'Group')
$ShowMembers = $group.psbase.invoke("members") | ForEach{
$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)
}
$ShowMembers | FT | Out-String
$richtextbox_Output.AppendText($ShowMembers)
}
display data
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: display data
Use "Lines" for a list.
Code: Select all
$buttonShowLocalAdmin_Click = {
$ADSIComputer = [ADSI]('WinNT://' + $PCNameBox.Text)
$group = $ADSIComputer.psbase.children.find('Administrators', 'Group')
$members = $group.psbase.invoke('members') |
ForEach{
$_.GetType().InvokeMember('Name', 'GetProperty', $null, $_, $null)
}
$richtextbox_Output.Lines = $members
}
Re: display data
thanks. That did work. I then tried the same trick on another button and it does not work. This does 2 things wrong. First, it displays the results all on one line. Second, it displays the results in black, not blue.
$buttonADGroupsMachineIsIn_Click={
$statusbar1.text = 'The query of active directory can take time, please wait.'
$richtextbox_Output.Clear()
$richtextbox_Output.SelectionColor = 'Blue'
$textPC = $PCNameBox.Text
$GetResults = Get-ADComputer $textPC -Properties * | Select-Object -ExpandProperty memberof
$GetResults | Out-String
$richtextbox_Output.Lines = $GetResults
$statusbar1.text = 'All done!'
}
$buttonADGroupsMachineIsIn_Click={
$statusbar1.text = 'The query of active directory can take time, please wait.'
$richtextbox_Output.Clear()
$richtextbox_Output.SelectionColor = 'Blue'
$textPC = $PCNameBox.Text
$GetResults = Get-ADComputer $textPC -Properties * | Select-Object -ExpandProperty memberof
$GetResults | Out-String
$richtextbox_Output.Lines = $GetResults
$statusbar1.text = 'All done!'
}
Re: display data
Less code is always a better place to start. Try not to code by superstition. Write only code lines that you understand.
Example:
Example:
Code: Select all
$buttonADGroupsMachineIsIn_Click={
$statusbar1.text = 'The query of active directory can take time, please wait.'
$richtextbox_Output.SelectionColor = 'Blue'
$richtextbox_Output.Lines = (Get-ADComputer $PCNameBox.Text -Properties memberof).memberof
$statusbar1.text = 'All done!'
}
Re: display data
Thanks. Your code still places everything onto 1 line and it is all black. and this actually ties into another issue we've been dealing with. We write all sorts of stuff to the RichText box. We make everything blue since it seems to look cleaner. When we dump a lot of data into the RichTextBox the first 40 or 50 lines are blue and then it changes to black.
Re: display data
Well you will need to spend some time researching how to use an RTB. You can just add RTF lines to the box and format the color and typeface as well as many other things.
If you always want blue text then use a textbox and set the color to blue.
I see no issues with the code I posted. Using Out-String or Format-Table will break the textbox or RTB because booth output strings and not arrays of lines.
If you always want blue text then use a textbox and set the color to blue.
I see no issues with the code I posted. Using Out-String or Format-Table will break the textbox or RTB because booth output strings and not arrays of lines.
Re: display data
Here is a sampler of methods for using an RTB:
- Attachments
-
- Demo-RTFColors.psf
- (28.47 KiB) Downloaded 173 times
Re: display data
Note also that "Multiline" must be set to "True"
Here is a slightly better sample that shows how to set the color globally.
Here is a slightly better sample that shows how to set the color globally.
- Attachments
-
- Demo-RTFColors.psf
- (29.12 KiB) Downloaded 135 times