Function ported from Powershell 5 to Powershell 7 fails with “object reference not set to an instance of an object”
问题 Following code works as expected in powershell 5.1: function Get-Say([String] $Message, [String] $Voice = "Microsoft Irina Desktop") { Add-Type -AssemblyName System.speech $speak = New-Object System.Speech.Synthesis.SpeechSynthesizer $speak.SelectVoice($Voice) $speak.Speak($Message) } However in powershell 7.1.0 (preview 5) execution is failing with "object reference not set to an instance of an object" and I'm actually lost. Googling does not help much since it looks like this error can be