用 PowerShell 制作代码雨动画

让绿色字符在控制台中不断下落。

Windows终端ASCII 字符画PowerShell低风险
运行这段一行脚本开始,按 Ctrl+C 停止。

01命令

命令
$ while ($true) { $line = -join (1..80 | ForEach-Object { [char](Get-Random -Minimum 33 -Maximum 126) }); Write-Host $line -ForegroundColor Green; Start-Sleep -Milliseconds 60 }

02作用说明

循环用 Get-Random 生成 80 个可打印随机字符,用 Write-Host 以绿色输出,再通过 Start-Sleep 暂停。调整范围或休眠时间可改变密度和速度,是练习循环和 .NET 类型的有趣示例。

03风险

风险低风险
使用条件Windows 10/11 with PowerShell 5.1 or PowerShell 7+
!注意: 循环会一直运行到被中断并持续占用控制台,不要无人值守地挂着。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • Get-Random
    Microsoft Learn · vendor-doc · 2026-09-20
    依据: Documents random number and collection selection, used to build each row.
  • Start-Sleep
    Microsoft Learn · vendor-doc · 2026-09-20
    依据: Pauses script execution; controls the animation speed.

最后验证: 2026-09-20 · 分类: 开发者

06相关方案