HI, good morning. cantgis has met you again.
Today, let's talk about the certificate. We use a lot of website verification certificates, including banks and entertainment websites. They will expire once a year.
In the certificate list in Internet Explorer, the set of expired certificates exists irregularly. How can we query and obtain and process them? The following cantgis provides you with this solution.
To obtain and find these certificates, we need to use the x.509 certificate providerMicrosoft. PowerShell. Security \ Certificate)
In powershell2.0, We need to manually clear these, X509store class objects, and use get-item:
$myCerts = Get-Item Cert:\CurrentUser\My
Next, to delete the certificate, you must open the x509 Certificate storage object through enumeration: openflags. This open () method: you can create a new storage or set access to the specified storage, of course, based on openflags)
By default, this store is read-only and cannot be deleted.
Member name |
Description |
|
|
IncludeArchived |
Open the X.509 certificate store and add an archived certificate. |
|
MaxAllowed |
Open the X.509 certificate store in the form that allows the highest level of access. |
|
OpenExistingOnly |
Only open an existing bucket. If no storage area exists, the Open method does not create a new storage area. |
|
ReadOnly |
Open the X.509 certificate store in read-only mode. |
|
ReadWrite |
Open the X.509 Certificate storage area in read/write mode. |
OK. We use
$myCerts.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
Use the following cmdlet to filter out the certificates that expired yesterday. $ mycerts has already pointed to the path. We can use it for reference, instead of making repeated encoding useless strings.
$today = Get-Date$ExpiredList = Get-ChildItem $myCerts.PSPath | Where-Object { $_.NotAfter -lt $today }
We don't want to call the pipe: where-object cmdlet command every time, because we don't need this
Delete the x.509 Certificate storage area of the certificate, and then execute the query.
ForEach ($Cert in $ExpiredList) { $myCerts.Remove($Cert)} $myCerts.Close() # We opened it, so we need to close it.
In powershell 3.0, we can integrate and execute
$ Today = Get-DateGet-ChildItem Cert: \ CurrentUser \ My | Where-Object NotAfter-lt $ today | Remove-Item # or Get-ChildItem Cert: \ CurrentUser \ My | ForEach-Object-begin {$ now = get-date}-process {if ($ PSItem. notAfter-lt $ now) Remove-Item
This article is from the "Cantgis" blog, please be sure to keep this source http://cantgis.blog.51cto.com/5788192/1228707