Skip to content

Instantly share code, notes, and snippets.

@Windos
Created October 9, 2019 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Windos/033d9878f9d922524fb5d3661d4edd04 to your computer and use it in GitHub Desktop.
Save Windos/033d9878f9d922524fb5d3661d4edd04 to your computer and use it in GitHub Desktop.
It's not pretty, or fast, but it'll work!
$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
@brettmillerb
Copy link

My implementation before looking at yours @Windos

Remarkably similar 👍

https://gist.github.com/brettmillerb/ac59d2ffc2f284438408b4845b7e3843

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment