Powershell

Today in the Feeds a Sharepoint 2010 Guru @-apreston posted a Tweet.

“Make Powershell Speak”

I went and quickly pasted in the code into Powershell and sure enough, it called up the Speech API and SPOKE! (which is actually a feature in Windows Accessibility)

Which shows the raw power of Powershell, the fact that if the feature is in Windows and there is some way programatically to access it, Powershell can use it.

So now of course, I thought this could be a cool function to add to Powershell as a regular feature.   And for those of you who are new, this is a way to see how EASY it is to add on features for yourself

So from Adam Preston’s Blog the command was simply

(new-object -com SAPI.SpVoice).speak(“Welcome to the SP2010 Blog”)

So if you would like to make this a regular function in Powershell just add this code into your profile or as a “Dot Sourced” script

function global:out-voice ($words) {

(new-object -com SAPI.SpVoice).speak($words)

}

There done! You see all we need to do? 

Enclose the original code between between {} (Parenth… Paren… Them funny brackety things)

Place the Take the information (text for example) you want to be passed through and replace that with a variable (In this case $words)

Place the word “Function” and a name to have the function called up by “out-voice” and in Round brackets (), the variables you are passing IN to the function (mattching the names of those you used in the code)

Placing GLOBAL: before the function name allows it to be called up “Globally”

 

So hopefully you can see how easy it is to create a function in Powershell and how much fun it is to play about thanks to Adam Preston we now have a simple yet elegant piece to add to our Powershell library.   The ability to speak

Sean
The Energized Tech.