我正在使用Powershell脚本来计算2个网络路径的每个子目录中文件的数量。当我在ISE Debug中运行它时,我的脚本工作得很好,但是当我尝试运行Powershell时,输出被截断,并且不提供计数。我很确定这是由于我在错误的位置关闭了foreach,但我似乎无法弄清楚这一点。我对Powershell非常陌生。运行PowerShell vs ISE时网络位置,不同输出的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
}