The first time my PSMenu function is called, the formatting appears correct. After the first loop iteration, the formatting somewhat randomly changes. It seems local to the first few "columns" of text. If you type enough $input sometimes the formatting will return to normal.
Things I have tried:
- multiple clear-hosts at beginning and end of loop
- adding a start-sleep .2 right before the loop repeats
I have figured out that the problem is with clear-host. I have tried using "Console.clear() and [System.Console]::Clear()" but neither work. I receive the error :
At line:3 char:20
+ console.clear()
+ ~
An expression was expected after '('.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ExpectedExpression
Here is a snippet example of the the format part of my code:
Function PSMenu{
Clear-Host
$title= 'Example REMOVAL TOOL'
$line = '_________________________________________'
$t=' '
write-host " $t$line$t " -BackgroundColor gray -ForegroundColor black;
Write-Host " $t$t $title $t $t " -BackgroundColor yellow -ForegroundColor black
write-host " $t$line$t " -BackgroundColor gray -ForegroundColor black;
Out-String;Out-String;
Write-Host "Give me some text and I will repeat this loop .('q' to quit.)" -ForegroundColor yellow
Write-Host "Computers cleansed: $successList `n`n"
}
Do{
PSMenu;
$input = Read-host "Enter some text"
write-host "Now I am doing something"
pause
}Until($input -eq 'q')