Sign up to Post
Load Recent Content
$ListOfServers = Get-ADComputer -Filter {Enabled -eq $True -and OperatingSystem -like "*Server*"} -SearchBase "DC=Domain,DC=com"
# If you want in in a text files containing server list or names
#$ListOfServers = Get-Content "c:\temp\serv.txt"
Foreach ($Server in $ListOfServers) {
Invoke-Command -ComputerName $Server -ScriptBlock {
# Get Certificate list and assign to a variable
$Certs = Get-ChildItem "Cert:\LocalMachine\My" -Recurse
#To get a list of all cert storage locations.
#(Get-ChildItem -Path "Cert:" -Recurse | Where-Object {($_).GetType().Name -eq 'X509Store'}).Name
# Loop through each object in $Certs
Foreach ($Cert in $Certs) {
# If The objects property "NotAfter" is older than the current time, delete
If ($Cert.NotAfter -lt (Get-Date)) {
$Cert | Remove-Item -WhatIf # Remove the -WhatIf to make it run for real.
}
}
}
}
191
Solutions
466
Contributors
We solve the world's technology problems through collaboration and learning.
For more than 20 years, we’ve been the leading authority and online provider of technology solutions. Users come to us from around the world to get answers to their technology problems, continue their education, and connect with global experts.
Take hold of your future.