【发布时间】:2015-09-28 16:30:27
【问题描述】:
我正在编写一个 Powershell 脚本来计算 2 个网络路径的每个子目录中的文件数。当我在 ISE Debug 中运行它时,我的脚本运行良好,但是当我尝试运行它时,Powershell 输出被截断并且它不提供计数。我很确定这是因为我在错误的位置关闭了 foreach,但我似乎无法弄清楚这一点。我对 Powershell 很陌生。
$dirs = "\\myserver\myshare\directory1" , "\\myserver\myshare\directory2"
$txt = "\\myserver\myshare\output.txt"
ForEach ($dir in $dirs)
{
(Get-ChildItem $dirs -recurse -Directory | ForEach-Object{
$props = @{
Folder = $_.FullName
Count = (Get-ChildItem -Path $_.Fullname -File | Measure- Object).Count
}
New-Object PSObject -Property $props } | Select-Object Folder , Count) | Format-Table -AutoSize | Out-File $txt
}
【问题讨论】:
标签: powershell foreach scripting