powershellpowershell-ise

While working in Powershell, how do I pause between list items?


I have been working on this for a while and I cannot find this utilization anywhere. I am using a powershell array and the foreach statement: @('program 1','program 2','program 3').foreach{winget show $_ -args}

I then want to have a pause between each one so I added ;sleep 1
This does not work. It pauses for 3s (based on this eg.) and then lists the items. What am I missing here?


Solution

  • Indeed it doesn't seem to respect the order, I don't know the technical reason why. You could either use a normal ForEach-Object

    'program 1','program 2','program 3' | ForEach-Object {
        winget show $_
        sleep 1
    }
    

    or force the output to go to the console instead of being "buffered"

    ('program 1','program 2','program 3').ForEach{
        winget show $_ | Out-Host
        sleep 1
    }