I'm stuck in a probably dumb problem :( Basically I have a function that write some output, and I would wait before exiting the script with a Read-Host command after the output of the function.
Here you are the code:
Function Get-FileMetaData {
<# modified script from:
NAME: Get-FileMetaData
AUTHOR: ed wilson, msft
LASTEDIT: 01/24/2014 14:08:24
Http://www.ScriptingGuys.com
Requires -Version 2.0
#>
Param($folders)
$tagList = @()
$tagListUnique = @()
foreach($folder in $folders) {
$i = 18 # attribute for Tags
$objShell = New-Object -ComObject Shell.Application
$objFolder = $objShell.namespace($folder.FullName)
foreach ($file in $objFolder.items()) {
if($objFolder.getDetailsOf($File, $i)) {
$objEntry = New-Object System.Object
$objEntry | Add-Member -type NoteProperty -name File -value $file.Path
$objEntry | Add-Member -type NoteProperty -name Tags -value $objFolder.getDetailsOf($File, $i)
$tagList += $objEntry
$tagListUnique += ($objFolder.getDetailsOf($File, $i) -split ";").trim()
}
}
}
Write-Output $tagList
Write-Output ""
Write-Output "unique tags"
Write-Output "-----------"
$tagListUnique | Sort-Object -unique
Read-Host "Press ENTER to exit"
}
$baseFolder = "C:\MyPictures"
Write-Host ""
Write-Host "Base folder: " $baseFolder
Get-FileMetaData -folder (Get-ChildItem $baseFolder -Recurse -Directory)
Basically it prints out the final statement "Press ENTER to exit" before the $tagList array.
I would like exactly the opposite, as in the order written in the code. With my limited ps skills, I understood there is something related in the different management of output "stream" and the input, but I cannot figure out how to "flush" all the output before it writes in the host.
Thanks in advance