Write a Powershell script that checks for a remote computer's certificate that is close…
- User
Write a Powershell script that checks for a remote computer's certificate that is close to expiration and manually re-enroll that certificate
Assistant
Here is a Powershell script that checks for a remote computer's certificate that is close to expiration and re-enrolls it:
$computer = "remotecomputername" $cert = Invoke-Command -ComputerName $computer -ScriptBlock { Get-ChildItem -Path Cert:\LocalMachine\My | Where-Object {$_.NotAfter -lt (Get-Date).AddDays(30)} | Select-Object -First 1 } if($cert) { Write-Host "Certificate $($cert.Subject) on $computer expires on $($cert.NotAfter) and will be renewed." Invoke-Command -ComputerName $computer -ScriptBlock { certutil -pulse } Write-Host "Certificate renewed successfully on $computer" } else { Write-Host "No certificates expiring within 30 days found on $computer" }This first gets any certificates on the remote computer that will expire within 30 days. If one is found, it prints a message and re-enrolls the certificate using certutil -pulse. Otherwise it prints a message that no expiring certs were found.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.