Last active
October 10, 2019 13:17
-
-
Save brettmillerb/ac59d2ffc2f284438408b4845b7e3843 to your computer and use it in GitHub Desktop.
Creates pscustomobject from filepath
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
using namespace System.Collections.Specialized | |
Get-ChildItem -Path C:\support\git\gitpersonal | Select-Object -ExpandProperty FullName | | |
function Split-FolderPath { | |
[CmdletBinding()] | |
param ( | |
[Parameter(ValueFromPipeline)] | |
[string[]] | |
$Path | |
) | |
process { | |
foreach ($location in $Path) { | |
$arr = $location -split '\\' | |
$dict = [OrderedDictionary]::new() | |
for ($i = 0; $i -lt $arr.Count; $i++) { | |
if ($i -eq 0) { | |
$dict.add('Root', $arr[$i]) | |
} | |
else { | |
$dict.add("Path$i", $arr[$i]) | |
} | |
} | |
[pscustomobject]$dict | |
} | |
} | |
} | |
Split-FolderPath -Path 'c:\users\brett\parent\child1\child2\child3' | |
Get-ChildItem -Path C:\support\git\gitpersonal -File -Recurse | | |
Select-Object -ExpandProperty FullName | Split-FolderPath |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment