Practice Exams for Windows

Practice Exams for Windows

Sunday, 10 July 2011

PowerShell Function: Out-Speaker

Here is a quick PowerShell Function that can be used to display read output via the speaker.

   1:  function Out-Speaker ([Parameter(Mandatory=$true,ValueFromPipeline=$true,ValuefromPipelinebyPropertyName=$true)][string]$Output) {
   2:      $Speaker = New-Object -comObject SAPI.SpVoice
   3:      $Speaker.Speak($output) | Out-Null
   4:  }
   5:  # Example - Uncomment and run to hear the example
   6:  # $Processes = (Get-Process).Count
   7:  # "There are $Processes processes running on your computer" | Out-Speaker

No comments:

Post a Comment