Skip to content

Instantly share code, notes, and snippets.

@brettmillerb
Last active October 10, 2019 13:17
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 brettmillerb/ac59d2ffc2f284438408b4845b7e3843 to your computer and use it in GitHub Desktop.
Save brettmillerb/ac59d2ffc2f284438408b4845b7e3843 to your computer and use it in GitHub Desktop.
Creates pscustomobject from filepath
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