我正在使用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
}