title: How to display a PowerShell output in List view using Windows Forms
body: <p>How do I output the <code>Get-ADUser -Filter &quot;GivenName -eq '$UserList' -or Surname -eq '$UserList'&quot; | select Name, SamAccountName</code> in to a list view.</p>
  <p>List view Variable is = $lwOutput</p>
  <pre><code>Add-Type -AssemblyName System.Windows.Forms
  [System.Windows.Forms.Application]::EnableVisualStyles()
  
  $Form                            = New-Object system.Windows.Forms.Form
  $Form.ClientSize                 = New-Object System.Drawing.Point(547,386)
  $Form.text                       = &quot;Form&quot;
  $Form.TopMost                    = $false
  
  $tbName                          = New-Object system.Windows.Forms.TextBox
  $tbName.multiline                = $false
  $tbName.width                    = 203
  $tbName.height                   = 20
  $tbName.location                 = New-Object System.Drawing.Point(218,37)
  $tbName.Font                     = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
  
  $lblName                         = New-Object system.Windows.Forms.Label
  $lblName.text                    = &quot;Enter First Name or Last Name&quot;
  $lblName.AutoSize                = $true
  $lblName.width                   = 25
  $lblName.height                  = 10
  $lblName.location                = New-Object System.Drawing.Point(14,40)
  $lblName.Font                    = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
  
  $lwOutput                        = New-Object system.Windows.Forms.ListView
  $lwOutput.text                   = &quot;listView&quot;
  $lwOutput.width                  = 476
  $lwOutput.height                 = 119
  $lwOutput.location               = New-Object System.Drawing.Point(32,115)
  
  $DGVOutput                       = New-Object system.Windows.Forms.DataGridView
  $DGVOutput.width                 = 480
  $DGVOutput.height                = 129
  $DGVOutput.location              = New-Object System.Drawing.Point(31,248)
  
  $btnSearch                       = New-Object system.Windows.Forms.Button
  $btnSearch.text                  = &quot;Search&quot;
  $btnSearch.width                 = 60
  $btnSearch.height                = 30
  $btnSearch.location              = New-Object System.Drawing.Point(361,71)
  $btnSearch.Font                  = New-Object System.Drawing.Font('Microsoft Sans Serif',10,[System.Drawing.FontStyle]([System.Drawing.FontStyle]::Bold))
  
  $Form.controls.AddRange(@($tbName,$lblName,$lwOutput,$DGVOutput,$btnSearch))
  
  $btnSearch.Add_Click({ btnGetUsers })
  
  function btnGetUsers { 
  
  
  $UserList = $tbName.Text
  Get-ADUser -Filter &quot;GivenName -eq '$UserList' -or Surname -eq '$UserList'&quot; | select Name, SamAccountName 
  
  
  
  }
  
  
  #Write your logic code here
  
  [void]$Form.ShowDialog()
  </code></pre>
  <p>Apologies for the basic question. Just trying out creating forms.</p>