Is there a way to beep in the console using POWERSHELL

5.3k Views Asked by At

I'm just starting to learn how to code in Powershell. So, how can I do dis?

I searched the MS website but it is not clear...

1

There are 1 best solutions below

0
mklement0 On

PowerShell has no dedicated command for emitting a beep.

Therefore, use [Console]::Beep(), which you note as an option. This relies on the fact that you have virtually unlimited access to .NET APIs from PowerShell:

[Console]::Beep()

An alternative, available in Windows PowerShell v5.1 (the latest and last version - not sure about earlier ones) and in all versions of PowerShell (Core), is to use escape sequence `a inside an expandable string ("...").

Write-Host -NoNewLine "`a"

Note: While "`a" alone would work too, it would also print a newline (which Write-Host -NoNewLine avoids).