Я бы порекомендовал удалить цикл while и установить переключатель.
Ваш цикл while просто постоянно пытался запускать оператор If
снова и снова.
$ErrorOccured8 = $false
$confirmation = Read-Host "Do you want to save the output to text file? [y/n]"
switch ($confirmation) {
"y"
{
try {
$ErrorActionPreference = 'Stop'
Write-Host("`Currently saving output to text. Please locate in temp folder.`n") -ForegroundColor darkmagenta
c:\temp\gsd.exe > "c:\temp\$($server)_$(((get-date).ToUniversalTime()).ToString("yyyyMMdd")).txt"
} catch {
Write-Host("`There has been some error. Kindly locate the file and refresh.`n") -ForegroundColor darkmagenta
$ErrorOccured8=$true
}
}
"n"
{
exit
}
}