Guest User

Untitled

a guest
Oct 19th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #requires -Version 2.0
  2.  
  3. #region Exported Cmdlets
  4.  
  5. <#
  6. .SYNOPSIS
  7. Creates a self-signed certificate and copies it into the trusted store.
  8. .DESCRIPTION
  9. Creates a self-signed certificate and copies it into the trusted store.
  10. .PARAMETER DnsName
  11. The DNS name for which a certicate should be issued. eg mysite.local
  12. .EXAMPLE
  13. # New-TrustedSelfSignedCertificate mysite.local
  14. Description
  15. -----------
  16. Creates a self-signed certificate for mysite.local
  17. #>
  18. function New-TrustedSelfSignedCertificate {
  19. [CmdletBinding()]
  20. param (
  21. [Parameter(Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Mandatory=$true)]
  22. [String] $DnsName,
  23.  
  24. [switch] $LocalMachine = $false
  25. )
  26.  
  27. process {
  28.  
  29. $ErrorActionPreference = "Stop"
  30.  
  31. $cert = New-SelfSignedCertificate -DnsName $DnsName -CertStoreLocation Cert:LocalMachineMy
  32.  
  33. if ($LocalMachine) {
  34. $CertLocation = "LocalMachine";
  35. } else {
  36. $CertLocation = "CurrentUser";
  37. }
  38.  
  39. # Cert provider does not support Copy-Item, so we'll copy it manually
  40. $dstStore = New-Object System.Security.Cryptography.X509Certificates.X509Store("Root", $CertLocation)
  41. $dstStore.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
  42. $dstStore.Add($cert)
  43. $dstStore.Close()
  44. }
  45. }
  46.  
  47. #endregion
  48.  
  49. #region Module Interface
  50. Export-ModuleMember New-TrustedSelfSignedCertificate
  51. #endregion
Add Comment
Please, Sign In to add comment