Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Friday Fun: Job Announcer

Posted on December 28, 2012

announcer-blueLast week I came across some people having fun with the SAPI.SPVoice COM object. This is the object that lets your computer "speak". If you've never played with this, it is very simple to do in PowerShell. The voice quality in Windows 7 and 8 is quite nice, as far as synthetic voices go.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!


$v = new-object -ComObject "SAPI.SPVoice"
$v.speak("Powershell rocks!")

This got me to wondering...what about using this as a job announcer? Instead of having to go back periodically to check the status of a background job, why not have the job notify me when it is finished? All I would need to do is add a few lines of code to the scriptblock to create the voice object and announce when the job is complete. Here's a sample.


#define a scriptblock for the job
$sb = {
Param($jobname)
#find all errors and warning in the system eventlog since midnight yesterday
Get-Eventlog -LogName System -EntryType Error,Warning -After (Get-Date).AddHours(-24).Date
#notify that the job has finished
(New-Object -ComObject SAPI.SPVoice).Speak("Thank you for your patience. Your job $jobname has finished.") | Out-Null
}
#define a name for the job that can be passed to the scriptblock
$jobname = "Get Latest Eventlogs"
Start-job -Name $jobname -ScriptBlock $sb -ArgumentList $jobname

The scriptblock could simply announce that the job is finished. If I only have a single job, that could be fine. But I wanted the scriptblock to be "aware" of what job it was running so I could have a more meaningful announcement. Thus, I pass the job name to the scriptblock so the voice object can use it in the announcement. It probably wouldn't be too difficult to build a wrapper function to incorporate the voice announcement with the scriptblock. But I'll leave that for you. If you come up with something, I hope you'll share it and let me know.


$v.speak("Enjoy and Happy New Year")


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

3 thoughts on “Friday Fun: Job Announcer”

  1. Pingback: Microsoft Most Valuable Professional (MVP) – Best Posts of the Week around Windows Server, Exchange, SystemCenter and more – #9 - TechCenter - Blog - TechCenter – Dell Community
  2. Pingback: Microsoft Most Valuable Professional (MVP) – Best Posts of the Week around Windows Server, Exchange, SystemCenter and more – #9 - Dell TechCenter - TechCenter - Dell Community
  3. Tim Bolton (@jsclmedave) says:
    December 31, 2012 at 10:49 am

    Nice! I actually did something similar for the same reason. I placed this little function into the script and it will reply with the users name that is running it.

    Function Done()
    {
    $MyName = $env:username
    $Tech=(Get-User $MyName).FirstName
    $Voice = new-object -ComObject SAPI.SpVoice;
    $Voice.Speak(“$Tech, Here are your results”) | Out-Null
    }

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d