| 1 | [CmdletBinding()] |
| 2 | param ( |
| 3 | [string]$OutputPath |
| 4 | ) |
| 5 | |
| 6 | $ErrorActionPreference = "Stop" |
| 7 | Set-StrictMode -Version Latest |
| 8 | # Set PSModulePath environment variable explicitly to work with PowerShell 7 |
| 9 | $env:PSModulePath = [Environment]::GetEnvironmentVariable('PSModulePath', 'Machine') |
| 10 | |
| 11 | $cert = New-SelfSignedCertificate -Type Custom -Subject "CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" -KeyUsage DigitalSignature -FriendlyName "WSL Dev cert" -CertStoreLocation "Cert:\CurrentUser\My" -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3", "2.5.29.19={text}") -HashAlgorithm "SHA256" -NotAfter (Get-Date).AddYears(10) |
| 12 | |
| 13 | Export-PfxCertificate -cert "Cert:\CurrentUser\My\$($cert.Thumbprint)" -FilePath $OutputPath -Password (New-Object System.Security.SecureString) | Out-Null |
| 14 | Remove-Item "Cert:\CurrentUser\My\$($cert.Thumbprint)" -DeleteKey | Out-Null |
| 15 | |
| 16 | Write-Host "Created new dev certificate in $OutputPath" |