# Get the local machine's Fully Qualified Domain Name (FQDN) $fqdn = [System.Net.Dns]::GetHostEntry('localhost').HostName # Define the certificate store location (LocalMachine or CurrentUser) $storeLocation = "LocalMachine" # Can be "LocalMachine" or "CurrentUser" $subfolder = "Certificates" # The subfolder where the certificate store resides $storeName = "Remote Desktop" # The "My" store is typically where Remote Desktop certificates are stored # Open the certificate store (Remote Desktop certificates are typically under "My" store) $certStore = Get-ChildItem -Path "Cert:\$storeLocation\$storeName" # Search for the certificate with the matching FQDN $certificate = $certStore | Where-Object { $_.Subject -like "*$fqdn*" } # If the certificate is found, delete it if ($certificate) { Write-Host "Found certificate for FQDN: $fqdn. Deleting certificate..." $certificate | Remove-Item Write-Host "Certificate for $fqdn has been deleted." } else { Write-Host "No certificate found for FQDN: $fqdn" }