When I execute the following code, assuming X:\ is a multi-level directory tree, it begins to throw strange errors on the second pass.
For example, let's assume X:\ has the following structure
X:\
--1stLevelDir
----2ndLevelDir
--Another1stLevelDir
function recurse{
param([System.IO.FileSystemInfo] $folder)
foreach ($dir in GCI $folder -Directory) {
Write-Output $dir.FullName
recurse $dir
}
}
recurse (get-item 'X:\')
That code produces the following output
X:\1stLevelDir
X:\1stLevelDir\2ndLevelDir
GCI : Cannot find path 'X:\2ndLevelDir' because it does not exist.
At foreach line