如何在PowerShell robocopy中加入进度条?

时间:2016-06-24 18:02:20

标签: powershell robocopy

我最近使用PowerShell制作了一个robocopy功能,因此我可以将文件从一台计算机传输到另一台计算机。但是,我无法弄清楚如何将进度条合并到我的脚本中,因为我做的有点不同。以下是该剧本的摘录:

$inputXML = @"
<Window x:Class="DataTransferV2.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:DataTransferV2"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525" Background="#FF0D94D2">
    <Grid>
        <Label x:Name="head_label" Content="Device Data Transfer" HorizontalAlignment="Left" Margin="151,10,0,0" VerticalAlignment="Top" FontSize="18" FontFamily="Segoe UI Black"/>
        <Button x:Name="checkall_button" Content="Check All" HorizontalAlignment="Left" Margin="212,49,0,0" VerticalAlignment="Top" Width="75"/>
        <CheckBox x:Name="documents_checkBox" Content="Documents" HorizontalAlignment="Left" Margin="57,102,0,0" VerticalAlignment="Top"/>
        <Button x:Name="start_button" Content="Start" HorizontalAlignment="Left" Margin="89,246,0,0" VerticalAlignment="Top" Width="88" Height="36"/>
        <Button x:Name="cancel_button" Content="Cancel" HorizontalAlignment="Left" Margin="205,246,0,0" VerticalAlignment="Top" Width="88" Height="36"/>
        <Button x:Name="exit_button" Content="Exit" HorizontalAlignment="Left" Margin="320,246,0,0" VerticalAlignment="Top" Width="88" Height="36"/>
    </Grid>
</Window>
"@

$inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N'  -replace '^<Win.*', '<Window'

[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
[xml]$XAML = $inputXML
#Read XAML

    $reader=(New-Object System.Xml.XmlNodeReader $xaml) 
  try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
catch{Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."}

#===========================================================================
# Store Form Objects In PowerShell
#===========================================================================

$xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)}


#===========================================================================
# Transfer Documents
#===========================================================================

Function global:Documents_Transfer{

if($WPFdocuments_checkBox.IsChecked -eq $true){

Write-Host "Transferring Documents..."

$quotation = ":"  
$source = "$DLetter$quotation\Users\$associd\Documents"
$destination = "C:\Users\$env:USERNAME\Documents"
$copy = "/COPY:DTO"
$files = "*.*"
$backup = "/B"
$reportextrafiles = "/X"
$verboseoutput = "V"
$fullpathname = "FP"
$mirror = "/MIR"
$backupmode = "/ZB"
$subfolders = "/E"
$Retries = "/R:2"
$consolewrite = "/TEE"

robocopy $source $destination $files $backup $reportextrafiles $verboseoutput $fullpathname $mirror $backupmode $subfolders $Retries $consolewrite

Write-Host "Documents Transferred"
}
}

$WPFstart_button.Add_Click({

[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
$associd = [Microsoft.VisualBasic.Interaction]::InputBox("Enter the associate ID:", "Verification", "")

[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
$DLetter = [Microsoft.VisualBasic.Interaction]::InputBox("Enter the external drive letter:", "Drive", "") 

Documents_Transfer

})

#===========================================================================
# Closes the form
#===========================================================================

$WPFexit_button.Add_Click({

$Form.Close()

})

#===========================================================================
# Shows the form
#===========================================================================

$Form.ShowDialog() | out-null

目前我只有一个试图跟踪某些进展的写主机。有人可以提供关于我如何跟踪这一进展的建议吗?先谢谢!

0 个答案:

没有答案