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. This way, 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
You can get a list of all of the COM objects on your computer with the following PowerShell code:
Get-ChildItem -Path HKLM:\Software\Classes -ErrorAction ` SilentlyContinue | Where-Object {$_.PSChildName -match '^\w+\.\w+$' –and ` (Get-Itemproperty "$($_.PSPath)\CLSID" -ErrorAction ` SilentlyContinue)} | Format...