Backup Script with GUI wont work

Hello Guys

I have written a Powershell backup script for school. It has a GUI. The backup works with robocopy. But when I start the script. The backup wont work. Can you please help me? I designed the GUI with PrimalFormsCE.

[/PRE]
#Generated Form Function
function GenerateForm {
########################################################################

Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.9.0

Generated On: 06.10.2016 08:41

Generated By: peamu

########################################################################

#region Import the Assemblies
[reflection.assembly]::loadwithpartialname(“System.Drawing”) | Out-Null
[reflection.assembly]::loadwithpartialname(“System.Windows.Forms”) | Out-Null
#endregion

#region variables
$form = New-Object System.Windows.Forms.Form
$notification_label = New-Object System.Windows.Forms.Label
$exit_button = New-Object System.Windows.Forms.Button
$restore_button = New-Object System.Windows.Forms.Button
$differetial_button = New-Object System.Windows.Forms.Button
$incremental_button = New-Object System.Windows.Forms.Button
$fullbackup_button = New-Object System.Windows.Forms.Button
$browse_dest = New-Object System.Windows.Forms.Button
$browse_source = New-Object System.Windows.Forms.Button
$dest_path = New-Object System.Windows.Forms.TextBox
$dest_label = New-Object System.Windows.Forms.Label
$source_path = New-Object System.Windows.Forms.TextBox
$source_label = New-Object System.Windows.Forms.Label
$title = New-Object System.Windows.Forms.Label
$openFileDialog1 = New-Object System.Windows.Forms.FolderBrowserDialog
$openFileDialog2 = New-Object System.Windows.Forms.FolderBrowserDialog
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
$robocopy = “${env:WINDIR}\System32\robocopy.exe”
$LogFile = $des_path
$inhalt = “The Backup was successfull.”
$inhalt404 = “The Backup wasn’t succussfull. Please Try again”
#endregion variables

###################################

Function to write Logfile

###################################

#----------------------------------------------
#Generated Event Script Blocks
#----------------------------------------------
#Provide Custom Code for events specified in PrimalForms.
$handler_Source_TextChanged=
{
#TODO: Place custom script here

}

$handler_textBox2_TextChanged=
{
#TODO: Place custom script here

}

$handler_label3_Click=
{
#TODO: Place custom script here

}

$incremental_button_OnClick=
{
#TODO: Place custom script here
write_log
$date = Get-Date -Format dd-MM-yy_HH/mm/ss
$folder_name = “Backup_$date”
$new_dest_path = “$des_path$folder_name”
New-Item -ItemType directory -Path $new_dest_path
start-process -FilePath $robocopy -ArgumentList “”$src_path" “$new_dest_path” /e /r:1 /w:1 /m"

}

$handler_browse_dest_Click=
{
#TODO: Place custom script here
if ($openfiledialog2.ShowDialog() -eq ‘OK’)
{
$dest_path.Text = $openFileDialog2.SelectedPath
$des_path = “$openFileDialog2.SelectedPath”
}

}

$handler_browse_source_Click=
{
#TODO: Place custom script here
if ($openfiledialog1.ShowDialog() -eq ‘OK’)
{
$source_path.Text = $openFileDialog1.SelectedPath
$src_path = “$openFileDialog1.SelectedPath”
}

}

$handler_form1_Load=
{
#TODO: Place custom script here

}

$handler_label4_Click=
{
#TODO: Place custom script here

}

$exit_button_OnClick=
{
#TODO: Place custom script here
$form.close()
}

$handler_label2_Click=
{
#TODO: Place custom script here

}

$restore_button_OnClick=
{
#TODO: Place custom script here
write_log
Start-process -FilePath $robocopy -ArgumentList “”$des_path" “$src_path” /e /r:1 /w:1 /copyall"
$notification = “The restore was successfull.”

$differetial_button_OnClick=
{
#TODO: Place custom script here
write_log
$date = Get-Date -Format dd-MM-yy_HH/mm/ss
$folder_name = “Backup_$date”
$new_dest_path = “$des_path$folder_name”
New-Item -ItemType directory -Path $new_dest_path
start-process -FilePath $robocopy -ArgumentList “”$src_path" “$new_dest_path” /e /r:1 /w:1 /a" #
$notification = “The diffetential backup was successfull.”

}

$fullbackup_button_OnClick=
{
#TODO: Place custom script here

$date = Get-Date -Format dd-MM-yy_HH/mm/ss
$folder_name = "Backup_$date"
$new_dest_path = "$des_path\$folder_name"
New-Item -ItemType directory -Path $new_dest_path
$result = Start-process -FilePath $robocopy  -ArgumentList "$src_path  $new_dest_path  /e /log:C:\log.TXT" #
[string]$errorcode = $result.ExitCode
if ($result.ExitCode -eq "0x00" ) {
	$msg = "The Backup was successfull"
	[System.Windows.Forms.MessageBox]::Show($msg,"PASSED",0)
	
} else {
	$msg = "ERROR 404 Fehlercode: $fehlercode"
	[System.Windows.Forms.MessageBox]::Show($msg,"FAILED",0)
}

}

$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
$form.WindowState = $InitialFormWindowState
}

#----------------------------------------------
#region Generated Form Code
$form.BackColor = [System.Drawing.Color]::FromArgb(255,255,0,0)
$form.BackgroundImage = [System.Drawing.Image]::FromFile(‘C:\Users\peamu\Desktop\Kitkatbackup\Kitkat-Chocolate-HD-Wallpapers-1024x576.jpg’)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 596
$System_Drawing_Size.Width = 1003
$form.ClientSize = $System_Drawing_Size
$form.DataBindings.DefaultDataSourceUpdateMode = 0
$form.Font = New-Object System.Drawing.Font(“Century Gothic”,11.25,0,3,1)
$form.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon(‘C:\Users\peamu\Desktop\Kitkatbackup\2n07xaq.png.ico’)
$form.Name = “form”
$form.RightToLeftLayout = $True
$form.Text = “KitKat-Backup”
$form.add_Load($handler_form1_Load)

$notification_label.BackColor = [System.Drawing.Color]::FromArgb(0,255,255,255)
$notification_label.DataBindings.DefaultDataSourceUpdateMode = 0
$notification_label.Font = New-Object System.Drawing.Font(“Century Gothic”,21.75,0,3,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 66
$System_Drawing_Point.Y = 516
$notification_label.Location = $System_Drawing_Point
$notification_label.Name = “notification_label”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 45
$System_Drawing_Size.Width = 481
$notification_label.Size = $System_Drawing_Size
$notification_label.TabIndex = 12
$notification_label.Text = $notification

$form.Controls.Add($notification_label)

$exit_button.BackColor = [System.Drawing.Color]::FromArgb(0,255,255,255)

$exit_button.DataBindings.DefaultDataSourceUpdateMode = 0

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 675
$System_Drawing_Point.Y = 442
$exit_button.Location = $System_Drawing_Point
$exit_button.Name = “exit_button”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 34
$System_Drawing_Size.Width = 217
$exit_button.Size = $System_Drawing_Size
$exit_button.TabIndex = 11
$exit_button.Text = “Exit”
$exit_button.UseVisualStyleBackColor = $False
$exit_button.add_Click($exit_button_OnClick)

$form.Controls.Add($exit_button)

$restore_button.BackColor = [System.Drawing.Color]::FromArgb(0,255,255,255)

$restore_button.DataBindings.DefaultDataSourceUpdateMode = 0
$restore_button.Font = New-Object System.Drawing.Font(“Century Gothic”,21.75,0,3,1)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 66
$System_Drawing_Point.Y = 431
$restore_button.Location = $System_Drawing_Point
$restore_button.Name = “restore-button”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 45
$System_Drawing_Size.Width = 422
$restore_button.Size = $System_Drawing_Size
$restore_button.TabIndex = 10
$restore_button.Text = “Restore”
$restore_button.UseVisualStyleBackColor = $False
$restore_button.add_Click($restore_button_OnClick)

$form.Controls.Add($restore_button)

$differetial_button.BackColor = [System.Drawing.Color]::FromArgb(0,255,255,255)

$differetial_button.DataBindings.DefaultDataSourceUpdateMode = 0
$differetial_button.Font = New-Object System.Drawing.Font(“Century Gothic”,18,0,3,1)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 675
$System_Drawing_Point.Y = 341
$differetial_button.Location = $System_Drawing_Point
$differetial_button.Name = “differetial_button”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 45
$System_Drawing_Size.Width = 217
$differetial_button.Size = $System_Drawing_Size
$differetial_button.TabIndex = 9
$differetial_button.Text = “Differential”
$differetial_button.UseVisualStyleBackColor = $False
$differetial_button.add_Click($differetial_button_OnClick)

$form.Controls.Add($differetial_button)

$incremental_button.BackColor = [System.Drawing.Color]::FromArgb(0,255,255,255)

$incremental_button.DataBindings.DefaultDataSourceUpdateMode = 0
$incremental_button.Font = New-Object System.Drawing.Font(“Century Gothic”,18,0,3,1)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 675
$System_Drawing_Point.Y = 274
$incremental_button.Location = $System_Drawing_Point
$incremental_button.Name = “incremental_button”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 45
$System_Drawing_Size.Width = 217
$incremental_button.Size = $System_Drawing_Size
$incremental_button.TabIndex = 8
$incremental_button.Text = "Incremental "
$incremental_button.UseVisualStyleBackColor = $False
$incremental_button.add_Click($incremental_button_OnClick)

$form.Controls.Add($incremental_button)

$fullbackup_button.BackColor = [System.Drawing.Color]::FromArgb(0,255,255,255)

$fullbackup_button.DataBindings.DefaultDataSourceUpdateMode = 0
$fullbackup_button.Font = New-Object System.Drawing.Font(“Century Gothic”,18,0,3,1)
$fullbackup_button.ForeColor = [System.Drawing.Color]::FromArgb(255,0,0,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 675
$System_Drawing_Point.Y = 208
$fullbackup_button.Location = $System_Drawing_Point
$fullbackup_button.Name = “fullbackup_button”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 45
$System_Drawing_Size.Width = 217
$fullbackup_button.Size = $System_Drawing_Size
$fullbackup_button.TabIndex = 7
$fullbackup_button.Text = “Fullbackup”
$fullbackup_button.UseVisualStyleBackColor = $False
$fullbackup_button.add_Click($fullbackup_button_OnClick)

$form.Controls.Add($fullbackup_button)

$browse_dest.BackColor = [System.Drawing.Color]::FromArgb(0,255,255,255)

$browse_dest.DataBindings.DefaultDataSourceUpdateMode = 0
$browse_dest.Font = New-Object System.Drawing.Font(“Century Gothic”,11,0,3,1)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 401
$System_Drawing_Point.Y = 343
$browse_dest.Location = $System_Drawing_Point
$browse_dest.Name = “browse_dest”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 30
$System_Drawing_Size.Width = 87
$browse_dest.Size = $System_Drawing_Size
$browse_dest.TabIndex = 6
$browse_dest.Text = “Browse”
$browse_dest.UseVisualStyleBackColor = $False
$browse_dest.add_Click($handler_browse_dest_Click)

$form.Controls.Add($browse_dest)

$browse_source.BackColor = [System.Drawing.Color]::FromArgb(0,255,255,255)

$browse_source.DataBindings.DefaultDataSourceUpdateMode = 0
$browse_source.Font = New-Object System.Drawing.Font(“Century Gothic”,11,0,3,1)

$browse_source.ImageAlign = 2
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 401
$System_Drawing_Point.Y = 227
$browse_source.Location = $System_Drawing_Point
$browse_source.Name = “browse_source”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 30
$System_Drawing_Size.Width = 87
$browse_source.Size = $System_Drawing_Size
$browse_source.TabIndex = 5
$browse_source.Text = “Browse”
$browse_source.TextAlign = 2
$browse_source.UseVisualStyleBackColor = $False
$browse_source.add_Click($handler_browse_source_Click)

$form.Controls.Add($browse_source)

$dest_path.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 66
$System_Drawing_Point.Y = 345
$dest_path.Location = $System_Drawing_Point
$dest_path.Name = “dest_path”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 26
$System_Drawing_Size.Width = 329
$dest_path.Size = $System_Drawing_Size
$dest_path.TabIndex = 4
$dest_path.Text = “Write the destination path of the Backup”
$dest_path.add_TextChanged($handler_textBox2_TextChanged)

$form.Controls.Add($dest_path)

$dest_label.BackColor = [System.Drawing.Color]::FromArgb(0,255,255,255)
$dest_label.DataBindings.DefaultDataSourceUpdateMode = 0
$dest_label.Font = New-Object System.Drawing.Font(“Century Gothic”,18,0,3,1)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 66
$System_Drawing_Point.Y = 304
$dest_label.Location = $System_Drawing_Point
$dest_label.Name = “dest_label”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 51
$System_Drawing_Size.Width = 460
$dest_label.Size = $System_Drawing_Size
$dest_label.TabIndex = 3
$dest_label.Text = “Destination Path”
$dest_label.add_Click($handler_label4_Click)

$form.Controls.Add($dest_label)

$source_path.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 66
$System_Drawing_Point.Y = 227
$source_path.Location = $System_Drawing_Point
$source_path.Name = “source_path”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 26
$System_Drawing_Size.Width = 329
$source_path.Size = $System_Drawing_Size
$source_path.TabIndex = 2
$source_path.Text = “Write the Path to backup.”
$source_path.add_TextChanged($handler_Source_TextChanged)

$form.Controls.Add($source_path)

$source_label.BackColor = [System.Drawing.Color]::FromArgb(0,255,255,255)
$source_label.DataBindings.DefaultDataSourceUpdateMode = 0
$source_label.Font = New-Object System.Drawing.Font(“Century Gothic”,18,0,3,1)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 66
$System_Drawing_Point.Y = 182
$source_label.Location = $System_Drawing_Point
$source_label.Name = “source_label”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 51
$System_Drawing_Size.Width = 157
$source_label.Size = $System_Drawing_Size
$source_label.TabIndex = 1
$source_label.Text = “Source Path”
$source_label.add_Click($handler_label3_Click)

$form.Controls.Add($source_label)

$title.BackColor = [System.Drawing.Color]::FromArgb(0,255,255,255)
$title.DataBindings.DefaultDataSourceUpdateMode = 0
$title.Font = New-Object System.Drawing.Font(“Century Gothic”,72,0,3,1)
$title.ForeColor = [System.Drawing.Color]::FromArgb(255,0,0,0)

$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = -45
$System_Drawing_Point.Y = 9
$title.Location = $System_Drawing_Point
$title.Name = “title”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 159
$System_Drawing_Size.Width = 1192
$title.Size = $System_Drawing_Size
$title.TabIndex = 0
$title.Text = “KitKat Backup”
$title.TextAlign = 32
$title.add_Click($handler_label2_Click)

$form.Controls.Add($title)

#endregion Generated Form Code

#Save the initial state of the form
$InitialFormWindowState = $form.WindowState
#Init the OnLoad event to correct the initial state of the form
$form.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form.ShowDialog()| Out-Null

} #End Function

#Call the Function
GenerateForm
[/PRE]
I am very Grateful, when you can help me.

greetings

xpxy15

Try updating the quotes around your Start-Process, you can do double quotes or leverage single quotes to have your string resolve properly:

Start-Process -FilePath $robocopy -ArgumentList '"$src_path" "$new_dest_path" /e /r:1 /w:1 /a'

Thanks Rob Simmers

I will try this out.

Post your psf on the sapien forums.