Powershell变量- verbose(如果它正在接收输入)



我创建了一个脚本,使用PowerShell压缩超过N天的文件。这样的:

param (
$dirPath, `
[int] $daysAgo, `
$logOutput=$dirPath+"old_reports.log", `
$fileExt
)
$curDate = Get-Date
$timeAgo = ($curDate).AddDays($daysAgo)
$files = Get-ChildItem -Recurse `
-Path $dirPath `
-Include *.$fileExt| `
Where-Object { $_.LastWriteTime -lt $timeAgo } | `
Select -ExpandProperty FullName
& 'C:Program Files7-Zip7Z.exe' a -t7z -mx9 old_reports.7z $files -bb1 -sdel
echo $files > $logOutput

它正在工作,但是,由于有许多文件,需要一段时间来填充$files变量。当它这样做时,提示符只显示一个闪烁的光标。因此,我不知道脚本是否真的在做什么,或者它被一个意外的点击暂停了。

是否有一种方法可以显示$files变量正在接收输入?

如果不重新构造命令——从而牺牲性能——我认为只有一个选择:

除了在变量$files中捕获文件信息对象外,还可以将它们打印到显示器上,这可以使用常见的-OutVariable参数:

# Output the files of interest *and* capture them in 
# variable $files, via -OutVariable
Get-ChildItem -Recurse `
-Path $dirPath `
-Include *.$fileExt| `
Where-Object { $_.LastWriteTime -lt $timeAgo } | `
Select -ExpandProperty FullName -OutVariable files

最新更新