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

Commit d0bbbdf

Browse files
committed
Merge pull request #9 from PowerShellOrg/PfxWithPassword
Added support for PFX files with passwords
2 parents ce11ad0 + 70056a7 commit d0bbbdf

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

DSCResources/StackExchange_CertificateStore/StackExchange_CertificateStore.psm1

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
function Get-TargetResource
42
{
53
[OutputType([Hashtable])]
@@ -70,15 +68,25 @@ function Set-TargetResource
7068
[parameter()]
7169
[ValidateSet('Present','Absent')]
7270
[string]
73-
$Ensure = 'Present'
71+
$Ensure = 'Present',
72+
[parameter()]
73+
[pscredential]
74+
$Password
7475
)
7576

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

7879
if ($Ensure -like 'Present')
7980
{
8081
Write-Verbose "Adding $path to $CertificateBaseLocation."
81-
Import-PfxCertificate -CertStoreLocation $CertificateBaseLocation -FilePath $Path
82+
83+
$passwordSplat = @{}
84+
if ($Password)
85+
{
86+
$passwordSplat['Password'] = $Password.Password
87+
}
88+
89+
Import-PfxCertificate -CertStoreLocation $CertificateBaseLocation -FilePath $Path @passwordSplat
8290
}
8391
else
8492
{
@@ -110,7 +118,10 @@ function Test-TargetResource
110118
[parameter()]
111119
[ValidateSet('Present','Absent')]
112120
[string]
113-
$Ensure = 'Present'
121+
$Ensure = 'Present',
122+
[parameter()]
123+
[pscredential]
124+
$Password
114125
)
115126

116127
$IsValid = $false
@@ -123,7 +134,18 @@ function Test-TargetResource
123134
if (Test-Path $CertificateLocation)
124135
{
125136
Write-Verbose "Found a matching certficate at $CertificateLocation"
126-
$IsValid = $true
137+
138+
$cert = Get-Item $CertificateLocation
139+
140+
if ($cert.HasPrivateKey)
141+
{
142+
Write-Verbose "Certficate at $CertificateLocation has a private key installed."
143+
$IsValid = $true
144+
}
145+
else
146+
{
147+
Write-Verbose "Certficate at $CertificateLocation does not have a private key installed."
148+
}
127149
}
128150
else
129151
{
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
[ClassVersion("1.0"), FriendlyName("CertificateStore")]
1+
[ClassVersion("1.1"), FriendlyName("CertificateStore")]
22
class StackExchange_CertificateStore : OMI_BaseResource
33
{
44
[Key] string Name;
55
[Key] string Path;
66
[write,ValueMap{"LocalMachine", "CurrentUser"},Values{"LocalMachine", "CurrentUser"}] string Location;
77
[write] string Store;
88
[write,ValueMap{"Present", "Absent"},Values{"Present", "Absent"}] string Ensure;
9+
[write,EmbeddedInstance("MSFT_Credential")] string Password;
910
};
10-
11-
12-

StackExchangeResources.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# RootModule = ''
1313

1414
# Version number of this module.
15-
ModuleVersion = '1.9.10.0'
15+
ModuleVersion = '1.9.11.0'
1616

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

0 commit comments

Comments
 (0)