28 lines
1.5 KiB
PowerShell
28 lines
1.5 KiB
PowerShell
# Get Certificate
|
|
$Path = ($pwd).Path
|
|
$CertificateName = (Get-ChildItem $Path | Where { $_.Name -like "*.crt" }).Name
|
|
certreq -accept "$Path\$CertificateName"
|
|
|
|
# Get Certificate details
|
|
$OldCert = Get-ChildItem Cert:\LocalMachine\My | Where-Object { $_.Subject -like "*remote.jwafurniture.com.au*" } | Select-Object -Property Thumbprint, Subject, @{n = 'ExpireInDays'; e = { ($_.notafter - (Get-Date)).Days } } | Where-Object { $_.ExpireInDays -lt 30 }
|
|
|
|
$NewCert = Get-ChildItem Cert:\LocalMachine\My | Where-Object { $_.Subject -like "*remote.jwafurniture.com.au*" } | Select-Object -Property Thumbprint, Subject, @{n = 'ExpireInDays'; e = { ($_.notafter - (Get-Date)).Days } } | Where-Object { $_.ExpireInDays -gt 300 }
|
|
|
|
# Update IIS Bindings
|
|
$bindingInfo = "IIS:\SSLBindings\*!443"
|
|
$newcert | Set-Item -Path $bindingInfo
|
|
|
|
#Remove Old Certificate
|
|
$Thumb = $OldCert.Thumbprint
|
|
Get-ChildItem Cert:\LocalMachine\My\$Thumb | Remove-Item
|
|
|
|
$Cert_PWD = ConvertTo-SecureString -String "Passw0rd!" -Force -AsPlainText
|
|
$exportPath = 'exported.pfx'
|
|
$iiscert = Get-ChildItem Cert:\LocalMachine\My\$Thumb
|
|
Export-PfxCertificate -Cert $iiscert -FilePath $exportPath -Password $Cert_PWD -Force
|
|
Set-RDCertificate -Role RDGateway -ImportPath "$exportPath" -Password $Cert_PWD -Force
|
|
Set-RDCertificate -Role RDWebAccess -ImportPath "$exportPath" -Password $Cert_PWD -Force
|
|
Set-RDCertificate -Role RDRedirector -ImportPath "$exportPath" -Password $Cert_PWD -Force
|
|
Set-RDCertificate -Role RDPublishing -ImportPath "$exportPath" -Password $Cert_PWD -Force
|
|
|