param ( [Parameter(Mandatory=$true, Position=0)] [string]$newCertname ) $confPath = "C:\ProgramData\PuppetLabs\puppet\etc\puppet.conf" $sslPath = "C:\ProgramData\PuppetLabs\puppet\etc\ssl" if (-not (Test-Path -Path $confPath)) { Write-Host "Path does not exist: $confPath" Exit } # Update the certname in puppet.conf (Get-Content -Path $confPath) | ForEach-Object { if ($_ -match "^certname\s*=") { $_ -replace "certname\s*=.*", "certname = $newCertname" } else { $_ } } | Set-Content -Path $confPath # Remove the SSL folder if (Test-Path -Path $sslPath -PathType Container) { Remove-Item -Path $sslPath -Recurse -Force } # Reload Puppet service Stop-Service -Name puppet Start-Sleep -Seconds 10 Start-Service -Name puppet