Powershell进度条,用于打印文件

时间:2018-08-15 15:31:04

标签: powershell

我正在尝试在目录中打印所有TEXT文件并显示进度条。  这是因为目录中通常可以有数百个文件。

目前,我有一个拼凑的脚本,我想将它们拼凑在一起。我在单独的区域中找到了位,但是我似乎无法弄清楚如何使其协同工作。

$Directory = "C:\Temp\Test"
$FileType = '*.txt'


Write-Host $FileType ' Files in Directory: '(Get-ChildItem -path $Directory -recurse -include *.txt).count


$TotalSteps = (Get-ChildItem -path $Directory -recurse -include *.txt).count
$Step       = 1
$StepText   = "Setting up print job"

$StatusText = '"Step $($Step.ToString().PadLeft($TotalSteps.Count.ToString().Length)) of $TotalSteps | $StepText"'
$StatusBlock = [ScriptBlock]::Create($StatusText)
$Task        = "Creating Progress Bar Script Block for Print Job"

Write-Progress -Id $Id -Activity $Activity -Status (& $StatusBlock) -CurrentOperation $Task -PercentComplete ($Step / $TotalSteps * 100)

Get-ChildItem -path $Directory -recurse -include *.txt | ForEach-Object {Start-Process -FilePath $_.fullname -Verb Print -PassThru | %{sleep 7;$_} | kill } 

0 个答案:

没有答案