djgamerr

CertCopy MailEnable

Sep 26th, 2021
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Stop-Service -DisplayName "MailEnable*"
  2.  
  3. $FileName = "C:\mypfx.pfx"
  4. $serverName = "CN=mail.xyzdomain.com"
  5. if (Test-Path $FileName)
  6. {
  7.   Remove-Item $FileName
  8. }
  9.  
  10. $mypwd = ConvertTo-SecureString -String "1234" -Force -AsPlainText
  11. $thumb = Get-ChildItem Cert:\LocalMachine\WebHosting `
  12.    | where{$_.Subject -eq $serverName}
  13. $final = $thumb.Thumbprint
  14. Get-ChildItem -Path cert:\LocalMachine\WebHosting\$final | Export-PfxCertificate -FilePath $FileName -Password $mypwd
  15.  
  16. try {
  17.   Get-ChildItem Cert:\LocalMachine\My | Where-Object {$_.Subject -eq $serverName} | Remove-Item
  18. } catch {}
  19.  
  20. Import-PfxCertificate -FilePath $FileName -CertStoreLocation Cert:\LocalMachine\My -Password $mypwd
  21.  
  22. if (Test-Path $FileName)
  23. {
  24.   Remove-Item $FileName
  25. }
  26.  
  27. Start-Service -DisplayName "MailEnable*"
Advertisement
Add Comment
Please, Sign In to add comment