Created
October 10, 2019 00:16
-
-
Save dfinke/fc6120bffa482c91c1d0c4ee4f4517b2 to your computer and use it in GitHub Desktop.
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
$parts = @() | |
$max=0 | |
foreach($file in (dir c:\temp -r)) { | |
$parts += ,$file.FullName.split("\") | |
$count = $parts[-1].Count | |
if($count -gt $max) {$max=$count} | |
} | |
$data = foreach ($part in $parts) { | |
$h=[ordered]@{} | |
for ($i = 0; $i -lt $max; $i++) { | |
$h["PropertyName$($i)"]='' | |
} | |
$count = $part.Count | |
for ($i = 0; $i -lt $count; $i++) { | |
$h["PropertyName$($i)"]=$part[$i] | |
} | |
[pscustomobject]$h | |
} | |
$xlfile = "$env:TEMP\parts.xlsx" | |
rm $xlfile -ErrorAction SilentlyContinue | |
Export-Excel -InputObject $data -Path $xlfile -AutoSize -Show |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment