71 lines
2.4 KiB
PowerShell
71 lines
2.4 KiB
PowerShell
#Script Robocopy con GUI
|
|
|
|
# Importamos el módulo necesario para crear la interfaz gráfica
|
|
Import-Module -Name 'Windows.Forms'
|
|
|
|
# Creamos una ventana
|
|
$Form = New-Object Windows.Forms.Form
|
|
$Form.Text = "Carlita Mogui"
|
|
$Form.Size = New-Object Drawing.Size(400, 250)
|
|
$Form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedSingle
|
|
$Form.MaximizeBox = $false
|
|
|
|
# Etiqueta y campo de texto para la ruta de origen
|
|
$Labelby = New-Object Windows.Forms.Label
|
|
$Labelby.Text = "Ruta de origen:"
|
|
$Labelby.Location = New-Object Drawing.Point(50, 50)
|
|
$Form.Controls.Add($Label2Source)
|
|
|
|
$LabelSource = New-Object Windows.Forms.Label
|
|
$LabelSource.Text = "Ruta de origen:"
|
|
$LabelSource.Location = New-Object Drawing.Point(10, 10)
|
|
$Form.Controls.Add($LabelSource)
|
|
|
|
$TextBoxSource = New-Object Windows.Forms.TextBox
|
|
$TextBoxSource.Location = New-Object Drawing.Point(10, 40)
|
|
$TextBoxSource.Size = New-Object Drawing.Size(360, 20)
|
|
$Form.Controls.Add($TextBoxSource)
|
|
|
|
# Etiqueta y campo de texto para la ruta de destino
|
|
$LabelDestination = New-Object Windows.Forms.Label
|
|
$LabelDestination.Text = "Ruta de destino:"
|
|
$LabelDestination.Location = New-Object Drawing.Point(10, 70)
|
|
$Form.Controls.Add($LabelDestination)
|
|
|
|
$TextBoxDestination = New-Object Windows.Forms.TextBox
|
|
$TextBoxDestination.Location = New-Object Drawing.Point(10, 100)
|
|
$TextBoxDestination.Size = New-Object Drawing.Size(360, 20)
|
|
$Form.Controls.Add($TextBoxDestination)
|
|
|
|
# Creamos una barra de progreso
|
|
$ProgressBar = New-Object Windows.Forms.ProgressBar
|
|
$ProgressBar.Location = New-Object Drawing.Point(10, 150)
|
|
$ProgressBar.Size = New-Object Drawing.Size(360, 20)
|
|
$Form.Controls.Add($ProgressBar)
|
|
|
|
# Creamos un botón para iniciar la copia
|
|
$Button = New-Object Windows.Forms.Button
|
|
$Button.Text = "Iniciar Copia"
|
|
$Button.Location = New-Object Drawing.Point(10, 180)
|
|
$Button.Add_Click({
|
|
# Obtenemos las rutas de origen y destino desde los campos de texto
|
|
$SourcePath = $TextBoxSource.Text
|
|
$DestinationPath = $TextBoxDestination.Text
|
|
|
|
# Ejecutamos Robocopy con los parámetros deseados
|
|
robocopy $SourcePath $DestinationPath /MIR /Z > $DestinationPath\log.txt
|
|
|
|
# Actualizamos la barra de progreso
|
|
$ProgressBar.Value = 100
|
|
$LabelSource.Text = "Copia completada"
|
|
|
|
# Abrir docuemto de logs
|
|
Start-Process 'C:\WINDOWS\system32\notepad.exe' $DestinationPath\log.txt
|
|
|
|
})
|
|
|
|
$Form.Controls.Add($Button)
|
|
|
|
# Mostramos la ventana
|
|
$Form.ShowDialog()
|