"Optimal" is a member of the CompressionLevel enum, not the CompressionMode enum, so your code should be:
[System.IO.MemoryStream] $output = New-Object System.IO.MemoryStream
$gzipStream = New-Object System.IO.Compression.GzipStream($output, [IO.Compression.CompressionLevel]::Optimal)
In your particular case, PowerShell is trying to be helpful and converts non-existent enum member names to $null
:
PS> $null -eq [IO.Compression.CompressionMode]::Optimal
True
PS> $null -eq [IO.Compression.CompressionMode]::NonExistentMember
True
so your original code is equivalent to:
[System.IO.MemoryStream] $output = New-Object System.IO.MemoryStream
$gzipStream = New-Object System.IO.Compression.GzipStream $output, $null
which gives the same exception as you got. The error isn't so much that it can't find a constructor overload with 2 parameters, it's more that it found multiple suitable overloads and couldn't choose which one to use (see the first two constructors in GZipStream Constructors).
Note also that I had to wrap the constructor parameters in round brackets - this changes the way PowerShell resolves which constructor to call somehow. I'm not sure of the exact details, but using the round brackets makes it work!
[System.IO.MemoryStream] $output = New-Object System.IO.MemoryStream
$gzipStream = New-Object System.IO.Compression.GzipStream($output, [IO.Compression.CompressionLevel]::Optimal)
Hope this helps.