Skip to content
This repository has been archived by the owner on May 15, 2018. It is now read-only.

Added support for PFX files with passwords #9

Merged
merged 1 commit into from
Aug 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


function Get-TargetResource
{
[OutputType([Hashtable])]
Expand Down Expand Up @@ -70,15 +68,25 @@ function Set-TargetResource
[parameter()]
[ValidateSet('Present','Absent')]
[string]
$Ensure = 'Present'
$Ensure = 'Present',
[parameter()]
[pscredential]
$Password
)

$CertificateBaseLocation = "cert:\$Location\$Store"

if ($Ensure -like 'Present')
{
Write-Verbose "Adding $path to $CertificateBaseLocation."
Import-PfxCertificate -CertStoreLocation $CertificateBaseLocation -FilePath $Path

$passwordSplat = @{}
if ($Password)
{
$passwordSplat['Password'] = $Password.Password
}

Import-PfxCertificate -CertStoreLocation $CertificateBaseLocation -FilePath $Path @passwordSplat
}
else
{
Expand Down Expand Up @@ -110,7 +118,10 @@ function Test-TargetResource
[parameter()]
[ValidateSet('Present','Absent')]
[string]
$Ensure = 'Present'
$Ensure = 'Present',
[parameter()]
[pscredential]
$Password
)

$IsValid = $false
Expand All @@ -123,7 +134,18 @@ function Test-TargetResource
if (Test-Path $CertificateLocation)
{
Write-Verbose "Found a matching certficate at $CertificateLocation"
$IsValid = $true

$cert = Get-Item $CertificateLocation

if ($cert.HasPrivateKey)
{
Write-Verbose "Certficate at $CertificateLocation has a private key installed."
$IsValid = $true
}
else
{
Write-Verbose "Certficate at $CertificateLocation does not have a private key installed."
}
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
[ClassVersion("1.0"), FriendlyName("CertificateStore")]
[ClassVersion("1.1"), FriendlyName("CertificateStore")]
class StackExchange_CertificateStore : OMI_BaseResource
{
[Key] string Name;
[Key] string Path;
[write,ValueMap{"LocalMachine", "CurrentUser"},Values{"LocalMachine", "CurrentUser"}] string Location;
[write] string Store;
[write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure;
[write,EmbeddedInstance("MSFT_Credential")] string Password;
};



2 changes: 1 addition & 1 deletion StackExchangeResources.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# RootModule = ''

# Version number of this module.
ModuleVersion = '1.9.10.0'
ModuleVersion = '1.9.11.0'

# ID used to uniquely identify this module
GUID = '7cec8ec5-91d8-435e-8136-51088d62fbed'
Expand Down