Skip to content

Instantly share code, notes, and snippets.

@chris-bradbury
Created August 2, 2022 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chris-bradbury/451196ee61fb02e16773bd0edc43af7f to your computer and use it in GitHub Desktop.
Save chris-bradbury/451196ee61fb02e16773bd0edc43af7f to your computer and use it in GitHub Desktop.
##-- Import Posh-ACME Module --##
Import-Module -Name Posh-ACME
##-- set the server. LE_STAGE or LE_PROD --##
Set-PAServer LE_PROD
##-- set up letsencrypt acount if it doesn't already exist --##
If(!(Get-PAAccount)){
New-PAAccount -AcceptTOS -Contact "<--email address for contact-->"
}
##-- set up cloudflare --##
$CloudFlareToken = @{ CFTokenInsecure = '<--cloudflare token-->' }
##-- generate the certificate setting using DNS verification through CloudFlare --##
New-PACertificate <--lansweeper URL--> -DnsPlugin Cloudflare -PluginArgs $CloudFlareToken -Force
##-- let's get the source of the pfx certificate --##
$PAPFXCert = Get-PACertificate | Select PfxFile
##-- set the certificate password --##
$Password = ConvertTo-SecureString -String "poshacme" -AsPlainText -Force
##-- import the certificate & grab the result --##
$PAPFXImport = Import-PfxCertificate -FilePath $PAPFXCert.PfxFile -CertStoreLocation Cert:\LocalMachine\My -Password $Password
##-- get the certificate object --##
$CertObj= Get-ChildItem "Cert:\LocalMachine\my\$($PAPFXImport.Thumbprint)"
##-- get the thumbprint of the certificate --##
$CertThumb = $CertObj.Thumbprint
##-- stop the IIS Express service --##
Stop-Service "IIS Express service"
##-- replace the thumbprint in the config --##
##-- path of the lansweeper config --##
$lansweeperConfig = "C:\Program Files (x86)\Lansweeper\IISexpress\IISExpressSvc.exe.config"
##-- read in the contents of the lansweeper config --##
$lansweeperConfigRead = Get-Content -Path $lansweeperConfig
##-- create the text to swap in to the config containing the new thumbprint --##
$lansweeperConfigReplacedText = "add key=`"CertificateThumbPrint`" value=`"$($CertThumb)`""
##-- replace the old thumbprint text with the new --##
$lansweeperConfigReplace = $lansweeperConfigRead -replace ".*\`"CertificateThumbPrint\`" value=\`".*\`"",$lansweeperConfigReplacedText
##-- write the replaced config back --##
Set-Content -Path $lansweeperConfig -Value $lansweeperConfigReplace
##-- start the IIS Express service --##
Start-Service "IIS Express service"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment