Windows Vista Forums

Retreive wmi data and show it in form label
  1. #1


    Jeroen Guest

    Retreive wmi data and show it in form label

    Hi guys,

    Well, the subject says pretty much everything there is to it: I have a
    script that generates a form and a label. I also have a gwmi statement that
    retreives some information (about AD, using an AD-specific cmdlet called
    "Get-QADUser"). It returns multiple properties (=fields) with multiple
    values. I want to enumerate this collection (of a single instance, ALWAYS) in
    the form's label.

    The relevant code snippet is as follows:

    # Start of code snippet
    $objAnswerPanel = New-Object System.Windows.Forms.Label
    $objAnswerPanel.Location = New-Object System.Drawing.Size(400,50)
    $objAnswerPanel.Size = New-Object System.Drawing.Size(350,450)
    $objForm.Controls.Add($objAnswerPanel)

    $objAnswerPanel.text = get-qaduser -ldapfilter '(samaccountname=johndoe)'

    # End of code snippet

    This doesn't work. However, in the powershell console, I get a decent
    collection out of this statement. So I'm guessing I'm presenting it wrong to
    the forms' label? It's very hard to find useful information about forms in
    PowerShell, so I decided to post this question here.

    Any help is greatly appreciated!
    Regards,
    Jeroen



      My System SpecsSystem Spec

  2. #2


    Shay Levy [MVP] Guest

    Re: Retreive wmi data and show it in form label

    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



      My System SpecsSystem Spec

  3. #3


    Jeroen Guest

    Re: Retreive wmi data and show it in form label

    Shay,

    Thanks for your reply!
    I would like to get the whole of the output you'd normally get in PS
    Console, in the label. Is it possible to either:
    a) Statically select properties gathered from the gwmi query and append them
    to the label?
    b) Enumerate automatically through all properties and put the collection in
    the label instantly?
    c) Use a textbox for this instead?

    Thanks!
    Jeroen


    "Shay Levy [MVP]" wrote:

    > 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
    >
    >
    >

      My System SpecsSystem Spec

  4. #4


    Shay Levy [MVP] Guest

    Re: Retreive wmi data and show it in form label

    Like that?


    $objForm = New-Object System.Windows.Forms.Form
    $objForm.width=500
    $objAnswerPanel = New-Object System.Windows.Forms.Label
    $objAnswerPanel.Size = New-Object System.Drawing.Size 450,350
    $objAnswerPanel.Location = New-Object System.Drawing.Size(10,50)
    $objAnswerPanel.Text = gps | select name,id | out-string
    $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> Shay,
    J>
    J> Thanks for your reply!
    J> I would like to get the whole of the output you'd normally get in PS
    J> Console, in the label. Is it possible to either:
    J> a) Statically select properties gathered from the gwmi query and
    J> append them
    J> to the label?
    J> b) Enumerate automatically through all properties and put the
    J> collection in
    J> the label instantly?
    J> c) Use a textbox for this instead?
    J> Thanks!
    J> Jeroen
    J> "Shay Levy [MVP]" wrote:
    J>

    >> Hi Jeroen,
    >>
    >> You need to get just the property value you want to set as the label
    >> text:
    >>
    >> $null=[reflection.assembly]::loadwithpartialname("System.Windows.Form
    >> s")
    >> $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


      My System SpecsSystem Spec

  5. #5


    Jeroen Guest

    Re: Retreive wmi data and show it in form label

    Shay,

    Hmm why didn't I think of that?
    Well thanks!

    One more question though.. I've tried changing the output component to:
    textbox, label and panel, but none of them are 'scrollable'. Output given IS
    larger than the output component. Is there any way to make it scrollable?

    Many thanks!

    Regards,
    Jeroen



    "Shay Levy [MVP]" wrote:

    > Like that?
    >
    >
    > $objForm = New-Object System.Windows.Forms.Form
    > $objForm.width=500
    > $objAnswerPanel = New-Object System.Windows.Forms.Label
    > $objAnswerPanel.Size = New-Object System.Drawing.Size 450,350
    > $objAnswerPanel.Location = New-Object System.Drawing.Size(10,50)
    > $objAnswerPanel.Text = gps | select name,id | out-string
    > $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> Shay,
    > J>
    > J> Thanks for your reply!
    > J> I would like to get the whole of the output you'd normally get in PS
    > J> Console, in the label. Is it possible to either:
    > J> a) Statically select properties gathered from the gwmi query and
    > J> append them
    > J> to the label?
    > J> b) Enumerate automatically through all properties and put the
    > J> collection in
    > J> the label instantly?
    > J> c) Use a textbox for this instead?
    > J> Thanks!
    > J> Jeroen
    > J> "Shay Levy [MVP]" wrote:
    > J>

    > >> Hi Jeroen,
    > >>
    > >> You need to get just the property value you want to set as the label
    > >> text:
    > >>
    > >> $null=[reflection.assembly]::loadwithpartialname("System.Windows.Form
    > >> s")
    > >> $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
    >
    >
    >

      My System SpecsSystem Spec

  6. #6


    Shay Levy [MVP] Guest

    Re: Retreive wmi data and show it in form label

    Try this:

    $textBox.Multiline = $True

    # scrollbar values
    #1 - horizontal
    #2 - vertical
    #3 - both

    $textBox1.ScrollBars = 3


    ---
    Shay Levy
    Windows PowerShell MVP
    http://blogs.microsoft.co.il/blogs/ScriptFanatic
    PowerShell Toolbar: http://tinyurl.com/PSToolbar



    J> Shay,
    J>
    J> Hmm why didn't I think of that?
    J> Well thanks!
    J> One more question though.. I've tried changing the output component
    J> to: textbox, label and panel, but none of them are 'scrollable'.
    J> Output given IS larger than the output component. Is there any way to
    J> make it scrollable?
    J>
    J> Many thanks!
    J>
    J> Regards,
    J> Jeroen
    J> "Shay Levy [MVP]" wrote:
    J>

    >> Like that?
    >>
    >> $objForm = New-Object System.Windows.Forms.Form
    >> $objForm.width=500
    >> $objAnswerPanel = New-Object System.Windows.Forms.Label
    >> $objAnswerPanel.Size = New-Object System.Drawing.Size 450,350
    >> $objAnswerPanel.Location = New-Object System.Drawing.Size(10,50)
    >> $objAnswerPanel.Text = gps | select name,id | out-string
    >> $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> Shay,
    >> J>
    >> J> Thanks for your reply!
    >> J> I would like to get the whole of the output you'd normally get in
    >> PS
    >> J> Console, in the label. Is it possible to either:
    >> J> a) Statically select properties gathered from the gwmi query and
    >> J> append them
    >> J> to the label?
    >> J> b) Enumerate automatically through all properties and put the
    >> J> collection in
    >> J> the label instantly?
    >> J> c) Use a textbox for this instead?
    >> J> Thanks!
    >> J> Jeroen
    >> J> "Shay Levy [MVP]" wrote:
    >> J>

    >>>> Hi Jeroen,
    >>>>
    >>>> You need to get just the property value you want to set as the
    >>>> label text:
    >>>>
    >>>> $null=[reflection.assembly]::loadwithpartialname("System.Windows.Fo
    >>>> rm
    >>>> s")
    >>>> $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


      My System SpecsSystem Spec

Retreive wmi data and show it in form label

Similar Threads
Thread Thread Starter Forum Replies Last Post
posting data to a web form kidkosmo VB Script 4 12 Feb 2010
Start a new thread to show form - Form never shows Curious .NET General 2 29 Oct 2009
Show calendar form another account Steve Live Mail 4 24 Oct 2009
Can'T submit form data from mail jcrsoft Vista mail 0 22 Aug 2008
password form data iMarriedMyself Vista security 0 10 Aug 2008