Using COM objects

You can also use the New-Object cmdlet to create an instance of a COM object. COM objects were used a lot in VBScript. In PowerShell, you can still use them to do things that you cannot do in native PowerShell. The following example will use the SAPI.SpVoice COM object to output a text as voice. It will say The script is finished. Append this piece of code at the end of your PowerCLI script, and you will hear your computer say that the script is finished so that you don't have to keep watching your computer screen. Isn't this cool?

PowerCLI C:\> $Voice = New-Object -ComObject SAPI.SpVoice
PowerCLI C:\> $Voice.Speak("The script is finished.") | Out-Null

The output of the $Voice.Speak() method is piped to the Out-Null cmdlet to ...

Get Learning PowerCLI - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.