Hi Jeroen,
You need to get just the property value you want to set as the label text:
$null=[reflection.assembly]::loadwithpartialname("System.Windows.Forms")
$objForm = New-Object System.Windows.Forms.Form
$objAnswerPanel = New-Object System.Windows.Forms.Label
$objAnswerPanel.Size = New-Object System.Drawing.Size 129,50
$objAnswerPanel.Location = New-Object System.Drawing.Size(10,50)
$objAnswerPanel.Text = (get-qaduser -samaccountname johndoe).samaccountname
$objForm.Controls.Add($objAnswerPanel)
$objForm.ShowDialog()| Out-Null
---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar:
http://tinyurl.com/PSToolbar
J> Hi guys,
J>
J> Well, the subject says pretty much everything there is to it: I have
J> a script that generates a form and a label. I also have a gwmi
J> statement that retreives some information (about AD, using an
J> AD-specific cmdlet called "Get-QADUser"). It returns multiple
J> properties (=fields) with multiple values. I want to enumerate this
J> collection (of a single instance, ALWAYS) in the form's label.
J>
J> The relevant code snippet is as follows:
J>
J> # Start of code snippet
J> $objAnswerPanel = New-Object System.Windows.Forms.Label
J> $objAnswerPanel.Location = New-Object System.Drawing.Size(400,50)
J> $objAnswerPanel.Size = New-Object System.Drawing.Size(350,450)
J> $objForm.Controls.Add($objAnswerPanel)
J> $objAnswerPanel.text = get-qaduser -ldapfilter
J> '(samaccountname=johndoe)'
J>
J> # End of code snippet
J>
J> This doesn't work. However, in the powershell console, I get a decent
J> collection out of this statement. So I'm guessing I'm presenting it
J> wrong to the forms' label? It's very hard to find useful information
J> about forms in PowerShell, so I decided to post this question here.
J>
J> Any help is greatly appreciated!
J> Regards,
J> Jeroen