I have the following function that gets a list of folder names and displays the results in a tabular fashion. Once that is done, I want to iterate through that list to do different things depending on the situation. Thus, the need to have a function so I don't have to repeat the code for every situation. The function:
Function Show-UsersFolders{
# Get list of folders where file is to be copied
$listOfFolders = Get-ChildItem -Directory | Select-Object Name
# Display total folders and display them in tabular form (8 columns)
Write-Host ("`nFound: " + $listOfFolders.Count + " users folders.")
$listOfFolders | Format-Wide -Column 8
, $listOfFolders
}
$myList = Show-UsersFolders
ForEach ($folder in $myList) {
Write-Host $folder
}
I get the following:
If I just call the funcion, nothing else (no ForEach loop afterwards), I get:
How do I go about printing the results and returning them so I can iterate through them later? I've read about how Powershell returns "everything", but I can't just make sense out of it so I can work with it.
Any help would be greatly appreciated.
Thanks in advance!