title: Synchronise 2 local Folders through a Powershell button
body: <p>I just want to make it clear, that i am completely new to powershell so sorry if i use wrong terms.</p>
  
  <p>I want to make a GUI where you can write a source folder Path and a target folder path, with a synchronise Button. I've tried multiple solutions from the internet but i cant seem to make it work. </p>
  
  <p>I want this all locally, so there is no server or anything involved.</p>
  
  <p>´´´</p>
  
  <pre><code>#Generated Form Function
  function GenerateForm {
  
  
  
  [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
  [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
  #endregion
  
  #region Generated Form Objects
  $form1 = New-Object System.Windows.Forms.Form
  $progressBar1 = New-Object System.Windows.Forms.ProgressBar
  $label2 = New-Object System.Windows.Forms.Label
  $textBox2 = New-Object System.Windows.Forms.TextBox
  $label1 = New-Object System.Windows.Forms.Label
  $textBox1 = New-Object System.Windows.Forms.TextBox
  $lbl_Eingabe = New-Object System.Windows.Forms.Label
  $btn_ok = New-Object System.Windows.Forms.Button
  $btn_cancel = New-Object System.Windows.Forms.Button
  $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
  #endregion Generated Form Objects
  
  #----------------------------------------------
  #Generated Event Script Blocks
  #----------------------------------------------
  #Provide Custom Code for events specified in PrimalForms.
  $x = $textBox1.Text
  $y = $textBox2.Text
  $handler_lbl_Eingabe_Click= 
  {
  #TODO: Place custom script here
  
  }
  
  $btn_ok_OnClick= 
  {
  Robocopy $x $y /MIR /FFT /Z /XA:H /W:5
  $form1.Close()
  
  }
  
  $handler_button1_Click= 
  {
      $form1.Close()
  
  }
  
  $OnLoadForm_StateCorrection=
  {#Correct the initial state of the form to prevent the .Net maximized form issue
      $form1.WindowState = $InitialFormWindowState
  }
  
  #----------------------------------------------
  #region Generated Form Code
  $System_Drawing_Size = New-Object System.Drawing.Size
  $System_Drawing_Size.Height = 321
  $System_Drawing_Size.Width = 626
  $form1.ClientSize = $System_Drawing_Size
  $form1.DataBindings.DefaultDataSourceUpdateMode = 0
  $form1.Name = "form1"
  $form1.Text = "Primal Form"
  
  $progressBar1.DataBindings.DefaultDataSourceUpdateMode = 0
  $System_Drawing_Point = New-Object System.Drawing.Point
  $System_Drawing_Point.X = 161
  $System_Drawing_Point.Y = 201
  $progressBar1.Location = $System_Drawing_Point
  $progressBar1.Name = "progressBar1"
  $System_Drawing_Size = New-Object System.Drawing.Size
  $System_Drawing_Size.Height = 23
  $System_Drawing_Size.Width = 352
  $progressBar1.Size = $System_Drawing_Size
  $progressBar1.TabIndex = 7
  
  $form1.Controls.Add($progressBar1)
  
  $label2.DataBindings.DefaultDataSourceUpdateMode = 0
  $label2.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",15.75,0,3,1)
  
  $System_Drawing_Point = New-Object System.Drawing.Point
  $System_Drawing_Point.X = 191
  $System_Drawing_Point.Y = 32
  $label2.Location = $System_Drawing_Point
  $label2.Name = "label2"
  $System_Drawing_Size = New-Object System.Drawing.Size
  $System_Drawing_Size.Height = 48
  $System_Drawing_Size.Width = 248
  $label2.Size = $System_Drawing_Size
  $label2.TabIndex = 6
  $label2.Text = "Ordner Synchronisieren"
  
  $form1.Controls.Add($label2)
  
  $textBox2.DataBindings.DefaultDataSourceUpdateMode = 0
  $System_Drawing_Point = New-Object System.Drawing.Point
  $System_Drawing_Point.X = 161
  $System_Drawing_Point.Y = 134
  $textBox2.Location = $System_Drawing_Point
  $textBox2.Name = "textBox2"
  $System_Drawing_Size = New-Object System.Drawing.Size
  $System_Drawing_Size.Height = 20
  $System_Drawing_Size.Width = 352
  $textBox2.Size = $System_Drawing_Size
  $textBox2.TabIndex = 3
  
  
  $form1.Controls.Add($textBox2)
  
  
  $label1.DataBindings.DefaultDataSourceUpdateMode = 0
  
  $System_Drawing_Point = New-Object System.Drawing.Point
  $System_Drawing_Point.X = 59
  $System_Drawing_Point.Y = 134
  $label1.Location = $System_Drawing_Point
  $label1.Name = "label1"
  $System_Drawing_Size = New-Object System.Drawing.Size
  $System_Drawing_Size.Height = 23
  $System_Drawing_Size.Width = 100
  $label1.Size = $System_Drawing_Size
  $label1.TabIndex = 3
  $label1.Text = "Zielverzeichnis:"
  
  $form1.Controls.Add($label1)
  
  $textBox1.DataBindings.DefaultDataSourceUpdateMode = 0
  $System_Drawing_Point = New-Object System.Drawing.Point
  $System_Drawing_Point.X = 161
  $System_Drawing_Point.Y = 83
  $textBox1.Location = $System_Drawing_Point
  $textBox1.Multiline = $True
  $textBox1.Name = "textBox1"
  $System_Drawing_Size = New-Object System.Drawing.Size
  $System_Drawing_Size.Height = 23
  $System_Drawing_Size.Width = 352
  $textBox1.Size = $System_Drawing_Size
  $textBox1.TabIndex = 3
  
  $form1.Controls.Add($textBox1)
  
  
  
  $lbl_Eingabe.DataBindings.DefaultDataSourceUpdateMode = 0
  
  $System_Drawing_Point = New-Object System.Drawing.Point
  $System_Drawing_Point.X = 12
  $System_Drawing_Point.Y = 83
  $lbl_Eingabe.Location = $System_Drawing_Point
  $lbl_Eingabe.Name = "lbl_Eingabe"
  $System_Drawing_Size = New-Object System.Drawing.Size
  $System_Drawing_Size.Height = 35
  $System_Drawing_Size.Width = 183
  $lbl_Eingabe.Size = $System_Drawing_Size
  $lbl_Eingabe.TabIndex = 2
  $lbl_Eingabe.Text = "Quellverzeichnis:"
  $lbl_Eingabe.TextAlign = 32
  $lbl_Eingabe.add_Click($handler_lbl_Eingabe_Click)
  
  $form1.Controls.Add($lbl_Eingabe)
  
  
  $btn_ok.DataBindings.DefaultDataSourceUpdateMode = 0
  
  $System_Drawing_Point = New-Object System.Drawing.Point
  $System_Drawing_Point.X = 402
  $System_Drawing_Point.Y = 250
  $btn_ok.Location = $System_Drawing_Point
  $btn_ok.Name = "btn_ok"
  $System_Drawing_Size = New-Object System.Drawing.Size
  $System_Drawing_Size.Height = 30
  $System_Drawing_Size.Width = 100
  $btn_ok.Size = $System_Drawing_Size
  $btn_ok.TabIndex = 1
  $btn_ok.Text = "Synchronisieren"
  $btn_ok.UseVisualStyleBackColor = $True
  $btn_ok.add_Click($btn_ok_OnClick)
  
  $form1.Controls.Add($btn_ok)
  
  
  $btn_cancel.DataBindings.DefaultDataSourceUpdateMode = 0
  
  $System_Drawing_Point = New-Object System.Drawing.Point
  $System_Drawing_Point.X = 508
  $System_Drawing_Point.Y = 250
  $btn_cancel.Location = $System_Drawing_Point
  $btn_cancel.Name = "btn_cancel"
  $System_Drawing_Size = New-Object System.Drawing.Size
  $System_Drawing_Size.Height = 30
  $System_Drawing_Size.Width = 86
  $btn_cancel.Size = $System_Drawing_Size
  $btn_cancel.TabIndex = 0
  $btn_cancel.Text = "Abbrechen"
  $btn_cancel.UseVisualStyleBackColor = $True
  $btn_cancel.add_Click($handler_button1_Click)
  
  $form1.Controls.Add($btn_cancel)
  
  #endregion Generated Form Code
  
  #Save the initial state of the form
  $InitialFormWindowState = $form1.WindowState
  #Init the OnLoad event to correct the initial state of the form
  $form1.add_Load($OnLoadForm_StateCorrection)
  #Show the Form
  $form1.ShowDialog()| Out-Null
  
  } #End Function
  
  #Call the Function
  GenerateForm
  </code></pre>
  
  <p>´´´</p>
  
  <p>I want it to show me the same files in the target folder as in the source folder, but just nothing happens and i dont have any idea why.</p>