Skip to content

Instantly share code, notes, and snippets.

@dfinke
Created October 10, 2019 00:16
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 dfinke/fc6120bffa482c91c1d0c4ee4f4517b2 to your computer and use it in GitHub Desktop.
Save dfinke/fc6120bffa482c91c1d0c4ee4f4517b2 to your computer and use it in GitHub Desktop.
$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