Oopps. I left the Split-Path off of my test code. That's goign to give you the filepath and, ultimately, the string that contains the filename.
So, to figure out what you're getting back from a command, you can see what the object is using something like this:
$x = ...whatever command...
Write-Output $x.GetType()
That Get-Child|Split-Path command isn't going to return a single filename. It'll return an array of FileInfo or DirectoryInfo objects, one array for each source directory. You can see that with the following modifications :
$source = @('Dir 1', 'Dir 2', 'Dir 3')
foreach ($x in $source)
{
$items = Get-ChildItem -Path $x | Split-Path -Leaf
Write-Output "ITEMS TYPE: " $items.GetType()
Write-Output $items
Write-Output
foreach ($item in $items)
{
Write-Output "ITEM TYPE: " $item.GetType()
Write-Output $item
}
}
So, to get the actual name of the directory, you would have to get its Name property. Replace the above inner foreach with this:
foreach ($item in $items)
{
Write-Output $item.Name
}