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 suppress output to the screen. The Out-Null
cmdlet sends the output to the NULL
device, which is the same as deleting it.
You can get a list of all of the COM objects on your computer with the following PowerShell code:
Get-ChildItem -Path HKLM...