Home > PowerShell, Tutorials > Make PowerShell Talk / Speak

Make PowerShell Talk / Speak

Have you ever run a long PowerShell script, minimized it, only to realize much later that an error caused it to stop? Rather than just using a color syntax red to display the error,  I wanted to hear it so I could switch back to the PowerShell window and see the error.

So how easy is it to make PowerShell speak? It’s almost identical to the .NET code I have in VB.net and C# on Make Your Computer Talk with VB.NET Application (and Source Code) using the SAPI.SpVoice class.

Here’s the one-liner:

(new-object -com SAPI.SpVoice).speak("Welcome to brangle dot com")

Now, if we want to write a function to generate to use whenever needed we could do so just like below. You might notice we used a global:functionName, this will allow the function to be in the global scope. If you don’t know what the global scope is, then just use, you’ll probably want it rather than not.

function global:talk ($message)  {
   (new-object -com SAPI.SpVoice).speak($message)
$error = "There was an error pinging the webserver"
  1. No comments yet.
  1. No trackbacks yet.