title: RoboCopy ForEach Loop with Tags?
body: <p>We have a PowerShell GUI, for backing up files. This GUI contains several checkboxes, each representing a file path and they can be checked or unchecked on demand.
  We have a function with a ForEach Loop which is called when Backup Button is clicked, and the source- and destination paths are then defined with the Tag property on each checkbox, and the Tag is "Split" in the function, so Powershell knows what to use as source, and what to use as destination.</p>
  
  <p>This works perfectly.
  The problem is, for one of the checkboxes we have several paths we want backed up, instead of just the one source defined in the Tag. For example, we want both C:\Src\Folder3 and D:\Src2\Folder3" backed up when the "Folder3" checkbox is checked.
  How would we do that?
  -Is it possible to add more tags to the checkbox? And if so, what changes would have to be made in the ForEach loop in regard to the Split?</p>
  
  <p>THANK YOU IN ADVANCE FOR ANY HELP PROVIDED!</p>
  
  <p>Full code here:</p>
  
  <pre><code>
  #ENABLE VISUALSTYLES#
  [System.Windows.Forms.Application]::EnableVisualStyles()
  
  #------------------------------------------------------------------------------FORM START------------------------------------------------------------------------------#
  
  $form = New-Object System.Windows.Forms.Form
  $form.Size = New-Object System.Drawing.Size(1450,842)
  $form.FormBorderStyle = "FixedDialog"
  $form.StartPosition = "CenterScreen"
  $form.Topmost = $False
  $form.add_Load($FormEvent_Load)
  
  $outputBox = New-Object System.Windows.Forms.TextBox 
  $outputBox.Location = New-Object System.Drawing.Size(200,110)
  $outputBox.Size = New-Object System.Drawing.Size(1220,643)
  $outputBox.MultiLine = $True 
  $outputBox.ScrollBars = "Both"
  $outputBox.BackColor = "White"
  $outputBox.ForeColor = "Black"
  $outputBox.WordWrap = $False
  $outputBox.ReadOnly = $True
  $outputBox.Font = New-Object System.Drawing.Font("Consolas",10)
  $Form.Controls.Add($outputBox)      
  
  #------------------------------------------------------------------------------FORM END------------------------------------------------------------------------------#
  
  #------------------------------------------------------------------------------BUTTONS START------------------------------------------------------------------------------#
  
  $CopyButton = New-Object System.Windows.Forms.Button
  $CopyButton.Location = New-Object System.Drawing.Size(10,200)
  $CopyButton.Size = New-Object System.Drawing.Size(180,35)
  $CopyButton.Text = "Backup selected files"
  $CopyButton.Add_Click({FILE_BACKUP})
  $form.Controls.Add($CopyButton)
  
  $CloseButton = New-Object System.Windows.Forms.Button
  $CloseButton.Location = New-Object System.Drawing.Size(10,250)
  $CloseButton.Size = New-Object System.Drawing.Size(180,35)
  $CloseButton.Text = "Close"
  $CloseButton.Add_Click({$form.Close()})
  $form.Controls.Add($CloseButton)
  
  
  #------------------------------------------------------------------------------BUTTONS END------------------------------------------------------------------------------#
  
  #------------------------------------------------------------------------------CHECKBOXES START------------------------------------------------------------------------------#
  
  $CheckBoxFolder1 = New-Object System.Windows.Forms.checkbox
  $CheckBoxFolder1.Location = New-Object System.Drawing.Size(10,15)
  $CheckBoxFolder1.Size = New-Object System.Drawing.Size(90,20)
  $CheckBoxFolder1.Checked=$True
  $CheckBoxFolder1.Text = "Path 1"
  $CheckBoxFolder1.Tag = "C:\src\Folder1&gt;C:\dest\Folder1"
  $form.Controls.Add($CheckBoxFolder1)
  
  $CheckBoxFolder2 = New-Object System.Windows.Forms.checkbox
  $CheckBoxFolder2.Location = New-Object System.Drawing.Size(10,35)
  $CheckBoxFolder2.Size = New-Object System.Drawing.Size(94,20)
  $CheckBoxFolder2.Checked=$True
  $CheckBoxFolder2.Text = "Path 2"
  $CheckBoxFolder2.Tag = "C:\src\Folder2&gt;C:\dest\Folder2"
  $form.Controls.Add($CheckBoxFolder2)
  
  $CheckBoxFolder3 = New-Object System.Windows.Forms.checkbox
  $CheckBoxFolder3.Location = New-Object System.Drawing.Size(10,55)
  $CheckBoxFolder3.Size = New-Object System.Drawing.Size(115,20)
  $CheckBoxFolder3.Checked=$True
  $CheckBoxFolder3.Text = "Path 3"
  $CheckBoxFolder3.Tag = "C:\src\Folder3&gt;C:\dest\Folder3"
  $form.Controls.Add($CheckBoxFolder3)
  
  #------------------------------------------------------------------------------CHECKBOXES END------------------------------------------------------------------------------#
  
  #------------------------------------------------------------------------------FUNCTIONS START------------------------------------------------------------------------------#
  
  function FILE_BACKUP {
  $CheckBoxes = @($CheckBoxFolder1, $CheckBoxFolder2, $CheckBoxFolder3)
  
      foreach ($CheckBox in $CheckBoxes)
      {
      $FilePath=$($CheckBox.Tag.Split("&gt;"))
       if ($CheckBox.Checked) 
          {
              robocopy $FilePath[0] $FilePath[1] /njh /njs /ndl /np /tee | ForEach-Object { $outputBox.AppendText($_ + "`r`n") }
          } 
          else 
          {
              $outputBox.AppendText("$($checkbox.Text) NOT SELECTED" + "`r`n")
          }
      }
  }
  
  #------------------------------------------------------------------------------FUNCTIONS END------------------------------------------------------------------------------#
  
  $form.ShowDialog()```
  </code></pre>