|
17 | 17 | [System.Management.Automation.PSCredential]
|
18 | 18 | $DatabaseCredential = (Get-Credential -Username ChocoUser -Message 'Create a credential for the ChocolateyManagement DB user (document this somewhere)'),
|
19 | 19 |
|
20 |
| - #Certificate to use for CCM service |
| 20 | + # Certificate to use for CCM service |
21 | 21 | [Parameter()]
|
| 22 | + [Alias('Thumbprint')] |
22 | 23 | [String]
|
23 | 24 | $CertificateThumbprint
|
24 | 25 | )
|
@@ -116,31 +117,27 @@ process {
|
116 | 117 | $hostName = [System.Net.Dns]::GetHostName()
|
117 | 118 | $domainName = [System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties().DomainName
|
118 | 119 |
|
119 |
| - if(-Not $hostName.endswith($domainName)) { |
| 120 | + if (-not $hostName.EndsWith($domainName)) { |
120 | 121 | $hostName += "." + $domainName
|
121 | 122 | }
|
122 | 123 |
|
123 | 124 | Write-Host "Installing Chocolatey Central Management Service"
|
124 |
| - if($CertificateThumbprint){ |
| 125 | + $chocoArgs = @('install', 'chocolatey-management-service', "--source='ChocolateyInternal'", '-y', "--package-parameters-sensitive=`"/ConnectionString:'Server=Localhost\SQLEXPRESS;Database=ChocolateyManagement;User ID=$DatabaseUser;Password=$DatabaseUserPw;'`"", '--no-progress') |
| 126 | + if ($CertificateThumbprint) { |
125 | 127 | Write-Verbose "Validating certificate is in LocalMachine\TrustedPeople Store"
|
126 |
| - if($CertificateThumbprint -notin (Get-ChildItem Cert:\LocalMachine\TrustedPeople | Select-Object -Expand Thumbprint)){ |
| 128 | + if (-not (Get-Item Cert:\LocalMachine\TrustedPeople\$CertificateThumbprint) -and -not (Get-Item Cert:\LocalMachine\My\$CertificateThumbprint)) { |
127 | 129 | Write-Warning "You specified $CertificateThumbprint for use with CCM service, but the certificate is not in the required LocalMachine\TrustedPeople store!"
|
128 | 130 | Write-Warning "Please place certificate with thumbprint: $CertificateThumbprint in the LocalMachine\TrustedPeople store and re-run this step"
|
129 |
| - throw "Certificate not in correct location....exiting." |
130 |
| - } |
131 |
| - else { |
| 131 | + throw "Certificate not in correct location... exiting." |
| 132 | + } elseif ($MyCertificate = Get-Item Cert:\LocalMachine\My\$CertificateThumbprint) { |
| 133 | + Write-Verbose "Copying certificate from 'Personal' store to 'TrustedPeople'" |
| 134 | + Copy-CertToStore $MyCertificate |
| 135 | + } else { |
132 | 136 | Write-Verbose "Certificate has been successfully found in correct store"
|
133 |
| - $chocoArgs = @('install', 'chocolatey-management-service', '-y', "--package-parameters-sensitive='/ConnectionString:Server=Localhost\SQLEXPRESS;Database=ChocolateyManagement;User Id=$DatabaseUser;Password=$DatabaseUserPw'") |
134 |
| - & Invoke-Choco @chocoArgs |
135 |
| - |
136 |
| - Set-CcmCertificate -CertificateThumbprint $CertificateThumbprint |
137 | 137 | }
|
| 138 | + $chocoArgs += @("--package-parameters='/CertificateThumbprint=$CertificateThumbprint'") |
138 | 139 | }
|
139 |
| - |
140 |
| - else { |
141 |
| - $chocoArgs = @('install', 'chocolatey-management-service', "--source='ChocolateyInternal'", '-y', "--package-parameters-sensitive=`"/ConnectionString:'Server=Localhost\SQLEXPRESS;Database=ChocolateyManagement;User ID=$DatabaseUser;Password=$DatabaseUserPw;'`"", '--no-progress') |
142 |
| - & Invoke-Choco @chocoArgs |
143 |
| - } |
| 140 | + & Invoke-Choco @chocoArgs |
144 | 141 |
|
145 | 142 | Write-Host "Installing Chocolatey Central Management Website"
|
146 | 143 | $chocoArgs = @('install', 'chocolatey-management-web', "--source='ChocolateyInternal'", '-y', "--package-parameters-sensitive=""'/ConnectionString:Server=Localhost\SQLEXPRESS;Database=ChocolateyManagement;User ID=$DatabaseUser;Password=$DatabaseUserPw;'""", '--no-progress')
|
|
0 commit comments