I've found out, that current code is not compatible with PS7 slightly.
Changing
$certbytes | Set-Content -Encoding Byte -Path $pfxPath -ea Stop
to
$certbytes | Set-Content -AsByteStream -Path $pfxPath -ea Stop
Fixed the issue for me.
Please consider changing it in repository.