title: Powershell popup to list of usernames
body: <p>I wish to have a powershell script that provides a popup message to a specific list of users.  I need to use a list of relevant users in a spreadsheet with their network username and not use Active Directory.  I have the powershell script to display a suitable message with a Warning icon and found to format the popup in a certain way I had to use a "FORM" and not a default popup messagebox.  Although the following two lines for the Warning icon would not work in the form so had to use a picture box</p>
  
  <pre><code>$WarningIcon = New-Object ([System.Windows.MessageBoxImage]::Warning)
  $Form.Controls.Add($WarningIcon)
  </code></pre>
  
  <p>The script for the form is as follows.  There is probably a cleaner way of creating a form like this but I am quite new to Powershell!</p>
  
  <pre><code>Add-Type -AssemblyName System.Windows.Forms
  $Form = New-Object system.Windows.Forms.Form
  $Form.Width = 700
  $Form.Height = 400
  $Form.BackColor = "#DCDCDC"
  
  $Form.Text = "System Restart Alert"
  
  $Font = New-Object System.Drawing.Font("Ariel",30, 
     [System.Drawing.FontStyle]::Bold::Underline)
  $FontB = New-Object System.Drawing.Font("Ariel",14, 
     [System.Drawing.FontStyle]::Bold)
  
  $Picture = (get-item ("C:\FA_Files\Windows_Warning_Exclamation9.jpg"))
  $img = [System.Drawing.Image]::Fromfile($Picture)
  $pictureBox = new-object Windows.Forms.PictureBox
  $pictureBox.Location = New-object System.Drawing.Size(160,30)
  $pictureBox.Height = "100"
  $pictureBox.Image = $img
  $Form.controls.add($pictureBox)
  
  $Label = New-Object System.Windows.Forms.Label
  $Label.Location = "260,30"
  $Label.Font = $Font
  $Label.ForeColor = "Red"
  $Label.Text = "WARNING!"
  $Label.AutoSize = $True
  $Form.Controls.Add($Label)
  
  $LabelB = New-Object System.Windows.Forms.Label
  $LabelB.Location = "100,130"
  $LabelB.Font = $FontB
  $LabelB.Text = "Due to essential maintenance system requires rebooting"
  $LabelB.AutoSize = $True
  $Form.Controls.Add($LabelB)
  
  $LabelC = New-Object System.Windows.Forms.Label
  $LabelC.Location = "100,160"
  $LabelC.Font = $FontB
  $LabelC.Text = "Please save all work immediately"
  $LabelC.AutoSize = $True
  $Form.Controls.Add($LabelC)
  
  $okButton = New-Object System.Windows.Forms.Button
  $okButton.Location = "300,280"
  $okButton.Font = "$FontB"
  $okButton.Size = "85,28"
  $okButton.Text = "Okay"
  
  $Form.Controls.Add($okButton)
  $okButton.Add_Click = ({$Form.Close()})
  $Form.ShowDialog()
  </code></pre>
  
  <p>I can retrieve a list of network usernames from the spreadsheet okay.  Below is an image of the csv content</p>
  
  <p><a href="https://i.stack.imgur.com/06vVT.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/06vVT.jpg" alt="enter image description here"></a></p>
  
  <p>But I have googled a lot and cannot find a way of sending the popup to the list of usernames retrieved from the spreadsheet.  So far I have tried the following where I have the form above set to the $msg varaiable and also tried having the form in another file and referencing that file in the $msg variable but it doesn't work</p>
  
  <pre><code>$csv = Import-csv "C:\FA_Files\NetNames.csv"
  
  foreach($line in $csv)
  {
    $name = $line.("Name")
    $netName = $line.("NetworkName")
    #Echo "Name is $name and Network Name is $netName"
    msg $netName $msg
  }
  </code></pre>
  
  <p>It also has to be on the username and not the machine name.  </p>
  
  <p>How do I correct this please?  </p>