Created
October 9, 2019 22:56
-
-
Save Windos/033d9878f9d922524fb5d3661d4edd04 to your computer and use it in GitHub Desktop.
It's not pretty, or fast, but it'll work!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Files = Get-ChildItem -Path C:\Temp -Recurse -File | |
$SplitFiles = @() | |
foreach ($File in $Files) { | |
$SplitFiles += ,$File.FullName.Split('\') | |
} | |
$NumColumns = ($SplitFiles | Measure-Object -Maximum -Property Count).Maximum | |
$Report = foreach ($SplitFile in $SplitFiles) { | |
$ReportProp = [Ordered] @{} | |
foreach ($Col in 0..$NumColumns) { | |
$ColumnName = 'Col{0}' -f $Col | |
if ($SplitFile[$Col]) { | |
$ReportProp[$ColumnName] = $SplitFile[$Col] | |
} else { | |
$ReportProp[$ColumnName] = '' | |
} | |
} | |
[PSCustomObject] $ReportProp | |
} | |
$Report | Export-Excel -Path 'C:\Temp\SplitPaths.xlsx' -BoldTopRow -AutoSize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My implementation before looking at yours @Windos
Remarkably similar 👍
https://gist.github.com/brettmillerb/ac59d2ffc2f284438408b4845b7e3843