Powershell随机颜色变化



以前从未使用过Powershell,我试图在Powershell中重新创建以下Bash脚本:

而为true;do head-c200/dev/urandom|od-An-w50-x|grep-E--color";([[:阿尔法:]][[:数字:]]({2}";;睡眠0.5;完成

这是我得到的,但我希望它将随机线变成红色,而不是每五个实例;

while(Get-Random)
{
Start-Sleep -Milliseconds 10
Write-Host -NoNewline "   " (get-random) 
Start-Sleep -Milliseconds 30    
Write-Host -NoNewline "   " (get-random) 
Start-Sleep -Milliseconds 10
Write-Host -NoNewline "   " (get-random) 
Start-Sleep -Milliseconds 30    
Write-Host -NoNewline "   " (get-random) 
Start-Sleep -Milliseconds 10
Write-Host -NoNewline "   " (get-random) -ForegroundColor red
}

任何关于我如何设置"-ForegroundColor红色";对于随机线路?

$color=@('gray','red')
while(Get-Random)
{   Start-Sleep -Milliseconds 10
Write-Host -NoNewline "   " (get-random) -ForegroundColor (Get-random $color)
}

最新更新