Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Forms 使用进度条和powershell下载_Forms_Powershell_Download - Fatal编程技术网

Forms 使用进度条和powershell下载

Forms 使用进度条和powershell下载,forms,powershell,download,Forms,Powershell,Download,我是PowerShell的新手,需要帮助 我正在尝试在脚本中应用进度条 我找到了这张纸条,上面显示了一个表格中的文件计数 $Path = "E:\AppTest" ## --- Put Folder-Path Here If (Test-Path $Path) { Write-Host Write-Host "Listing All Files Found In $Path" -ForegroundColor "Yellow" Write-Host "==================

我是PowerShell的新手,需要帮助 我正在尝试在脚本中应用进度条 我找到了这张纸条,上面显示了一个表格中的文件计数

$Path = "E:\AppTest"    ## --- Put Folder-Path Here 
If (Test-Path $Path) {
Write-Host
Write-Host "Listing All Files Found In $Path" -ForegroundColor "Yellow"
Write-Host "=========================================" -ForegroundColor "Yellow"
Add-Type -assembly System.Windows.Forms
## -- Create The Progress-Bar
$ObjForm = New-Object System.Windows.Forms.Form
$ObjForm.Text = "Demonstration of Progress-Bar In PowerShell"
$ObjForm.Height = 100
$ObjForm.Width = 500
$ObjForm.BackColor = "White"

$ObjForm.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedSingle
$ObjForm.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen

## -- Create The Label
$ObjLabel = New-Object System.Windows.Forms.Label
$ObjLabel.Text = "Starting. Please wait ... "
$ObjLabel.Left = 5
$ObjLabel.Top = 10
$ObjLabel.Width = 500 - 20
$ObjLabel.Height = 15
$ObjLabel.Font = "Tahoma"
## -- Add the label to the Form
$ObjForm.Controls.Add($ObjLabel)

$PB = New-Object System.Windows.Forms.ProgressBar
$PB.Name = "PowerShellProgressBar"
$PB.Value = 0
$PB.Style="Continuous"

$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 500 - 40
$System_Drawing_Size.Height = 20
$PB.Size = $System_Drawing_Size
$PB.Left = 5
$PB.Top = 40
$ObjForm.Controls.Add($PB)
## -- Show the Progress-Bar and Start The PowerShell Script
$ObjForm.Show() | Out-Null
$ObjForm.Focus() | Out-NUll
$ObjLabel.Text = "Starting. Please wait ... "
$ObjForm.Refresh()
Start-Sleep -Seconds 1

## -- Execute The PowerShell Code and Update the Status of the Progress-Bar

$Result = Get-ChildItem -Path $Path -File -Recurse -Force | Select Name, @{Name="Path";Expression={$_.FullName}}
$Counter = 0
ForEach ($Item In $Result) {
    ## -- Calculate The Percentage Completed
    $Counter++
    [Int]$Percentage = ($Counter/$Result.Count)*100
    $PB.Value = $Percentage
    $ObjLabel.Text = "Recursive Search: Writing Names of All Files Found Inside $Path"
    $ObjForm.Refresh()
    Start-Sleep -Milliseconds 150
    # -- $Item.Name
    "`t" + $Item.Path
}
$ObjForm.Close()
Write-Host "`n"} Else {
Write-Host
Write-Host "`t Cannot Execute The Script." -ForegroundColor "Yellow"
Write-Host "`t $Path Does Not Exist in the System." -ForegroundColor "Yellow"
Write-Host}
我创建了一个类似这样的表单(为了更清晰,我缩小了它的范围),我希望能够在表单的进度条中显示下载内容 上面的命令显示count命令 如何将其应用于下载和进度条

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()

$Form                            = New-Object system.Windows.Forms.Form
$Form.ClientSize                 = '1370,720'
$Form.TopMost                    = $true
$Form.StartPosition = "CenterScreen"

$btn                      = New-Object system.Windows.Forms.Button
$btn.Text                 = 'download'
$btn.width                = 300
$btn.height               = 130
$btn.location             = New-Object System.Drawing.Point(716,485)
$btn.Font                 = 'Microsoft Sans Serif,10'

$ProgressBar                     = New-Object system.Windows.Forms.ProgressBar
$ProgressBar.width               = 703
$ProgressBar.height              = 37
$ProgressBar.location            = New-Object System.Drawing.Point(345,660)
$ProgressBar.Maximum             = 100
$ProgressBar.Minimum             = 0
$progressBar.Step                = 1
$i = 0

$Form.Controls.Add($ProgressBar)
$Form.controls.AddRange(@($btn,$ProgressBar))

$btn.Add_Click({Invoke-WebRequest -Uri "https://speed.hetzner.de/100MB.bin"  -OutFile "C:\script\100MB.bin"})

[void]$Form.ShowDialog()

有人能帮我做这个吗

对不起,我试着去理解,但是不能。你到底想达到什么目的?现在您有了一个进度条,可以列出所提供路径中的所有项目。我在你的脚本中没有看到任何下载部分。下载什么和到哪里?是否要将此代码添加到您之前创建的表单中?我编辑了我的帖子,以进一步澄清