Try it like this:
Write-Host $number -ForegroundColor $(if ($number -eq 100) {'Green'} else {'Red'})
You don't want to use {}
in this case. ForegroundColor does not accept a scriptblock and it is not pipeline bound. Besides you're not piping anything into Write-Host. A subexpression $()
allows you to evaluate statements like if, foreach, etc.