$RemotePath = "c:\temp"
$ExportFilePath = "c:\temp\output.csv"
$tree = Get-ChildItem -Path $RemotePath -Recurse
Write-Host "Number of Directory and files in $RemotePath : " -ForegroundColor Green -NoNewline
Write-host "$($tree.count)" -ForegroundColor Yellow
Write-host "Exporting list in a .csv file" -ForegroundColor green
$tree | Export-Csv -Path $ExportFilePath -Encoding UTF8 -Delimiter ";" -NoTypeInformation # using -encoding to avoid of accents. using -delimiter because in Fr, it's easier to improve presentation with excel.
Something simple like this ? I don't think so.
$tree = Get-ChildItem -Path $RemotePath -Recurse -Directory
$result = @() # initialize a array
foreach ($dir in $tree)
{
$object = New-Object -TypeName PSObject # create a PSObject and feed it
$object | Add-Member -MemberType NoteProperty -Name 'Dir' -Value $($dir.name)
$object | Add-Member -MemberType NoteProperty -Name 'DirFullName' -Value $($dir.Fullname)
$object | Add-Member -MemberType NoteProperty -Name 'NberOfFilesInDir' -Value (Get-ChildItem -Path $($dir.fullName) -File).count
$result += $object # add the PSObject to the Array
}
$result
$result | Export-Csv -Path $ExportFilePath -Encoding UTF8 -Delimiter ";" -NoTypeInformation # using -encoding to avoid of accents. using -delimiter because in Fr, it's easier to improve presentation with excel.
Perhaps something like this.
Oliv