Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #requires -Version 2.0
- #region Exported Cmdlets
- <#
- .SYNOPSIS
- Creates a self-signed certificate and copies it into the trusted store.
- .DESCRIPTION
- Creates a self-signed certificate and copies it into the trusted store.
- .PARAMETER DnsName
- The DNS name for which a certicate should be issued. eg mysite.local
- .EXAMPLE
- # New-TrustedSelfSignedCertificate mysite.local
- Description
- -----------
- Creates a self-signed certificate for mysite.local
- #>
- function New-TrustedSelfSignedCertificate {
- [CmdletBinding()]
- param (
- [Parameter(Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Mandatory=$true)]
- [String] $DnsName,
- [switch] $LocalMachine = $false
- )
- process {
- $ErrorActionPreference = "Stop"
- $cert = New-SelfSignedCertificate -DnsName $DnsName -CertStoreLocation Cert:LocalMachineMy
- if ($LocalMachine) {
- $CertLocation = "LocalMachine";
- } else {
- $CertLocation = "CurrentUser";
- }
- # Cert provider does not support Copy-Item, so we'll copy it manually
- $dstStore = New-Object System.Security.Cryptography.X509Certificates.X509Store("Root", $CertLocation)
- $dstStore.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
- $dstStore.Add($cert)
- $dstStore.Close()
- }
- }
- #endregion
- #region Module Interface
- Export-ModuleMember New-TrustedSelfSignedCertificate
- #endregion
Add Comment
Please, Sign In to add comment