I have a powershell script that used to work. I tried adding a try --> finally part to encapsulate some script blocks in order to handle Ctrl+C during a for each part of the operation. After that when it reaches the finally part it exits the moment I mention an object array that is declared at the start of the script (not inside the try part). I tried using debug and when I put the breakpoint on the object mention and it reaches it I can see the objects inside. Then I press F11 and it stops, with no error and no exception anywhere..
$Artists = @()
...
finally { ### Write CSV regardless of script break ###
write-host "VC-Artists file maintenance.." -ForegroundColor "Green"
pause; $Artists.count; pause;....
A short example that I came up that shows this behavior is the following:
$Artists = @(); try { $i=1; while($true) { "Artist..$($i)"; $Artists += New-Object PSObject -Property @{ Artist = "test";idArtist = $i;Style = "pop";Genre = {"Jazz", "Pop"};ArtistAlternate = "test2";discogsidArtist = $i }; $i++; Start-Sleep -Seconds 1 } } finally { write-host "Ended work."; $Artists.count; pause }
when Ctr+C is pressed it stops, executes the write host but nothing after that (at least for me).
Any ideas?