PowerShell

Do-Speak: Start talking with Remote Computers (System.Speech)

In this article I’ll show you how to use a very simple command that works for the local computer and remote computers and lets your computers speak.

Sometimes I have strange ideas. I found the System.Speech Class, and used it for let my computer speak. Some of you may have read my other article about informing users with text messages that I’ve described here: Active Directory: Send Messages to all currently logged on Users (msg.exe). Now we do something different, we inform our users with “Remote Talking”.

Function Do-Speak

Do-Speak enables you to let your computer speak something. Do-Speak also supports remote speaking. That said, you are able to send a text message to a remote computer which will then output your message via audio. Make sure Windows Remotemanagement (WinRm) is enabled on your client computers. In Windows Server 2012 and above it’s enabled by default. More about enabling WinRm with GPO see: Group Policies: Enabling WinRM for Windows Client Operating Systems (Windows 10, Windows 8, Windows 7)

Examples

Local Computer


Do-Speak

Capture.PNG

Remote Computer

When you send your audio text message to a remote computer you usually have to authenticate with an administrator account. Therefore I’ve implemented a command to ask you for your credentials before you can send the message.

And here in action:


Do-Speak -Computer client01

Unbenannt.PNG

Unbenannt.PNG

The function Do-Speak

Copy this code in PowerShell ISE and press the green button. Have fun with it.


Function Do-Speak {

[CmdletBinding()]

param
(

[Parameter(Position=0)]

$Computer

)

If (!$computer)

{

$Text=Read-Host 'Enter Text'

[Reflection.Assembly]::LoadWithPartialName('System.Speech') | Out-Null
$object = New-Object System.Speech.Synthesis.SpeechSynthesizer
$object.Speak($Text)

}

else {

$cred=Get-Credential

$PS=New-PSSession -ComputerName $Computer -Credential $cred

Invoke-Command -Session $PS {
$Text=Read-Host 'Enter Text'

[Reflection.Assembly]::LoadWithPartialName('System.Speech') | Out-Null
$object = New-Object System.Speech.Synthesis.SpeechSynthesizer
$object.Speak($Text)
}

}

}

Make it permanent

If you like my approach open PowerShell ISE. Copy the function into your ISE session. Create a folder in C:\Program Files\Windows PowerShell\Modules and save the code as psm1 file. Make sure that your file name and folder name match.

Unbenannt.PNG

From now on, PowerShell will load the custom module at startup.

4 replies »

  1. hello, i have a problem:
    “do-speak : The term ‘do-speak’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    At line:1 char:1
    + do-speak
    + ~~~~~~~~
    + CategoryInfo : ObjectNotFound: (do-speak:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException”
    how to resolv? pls, thankss

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.