Reputation: 448
I am trying to check if a particular certificate is installed on my machine. I am using the following powershell script
SET-LOCATION CERT:\LOCALMACHINE\my
$certificate = "CN=*XXXX"
$ListOfCertificate = GET-CHILDITEM | Select-Object -Property Subject
$ListOfCertificate.ForEach({if($_==$certificate) {Write-Output "Certficate Successfully Installed"} })
ListOfCertifiacte Object looks like this:
Thumbprint Subject
---------- -------
yu39B5646D569XXXXXX
ui05F79VVVVVVVVVV CN=*XXXX
6kj6A3AAAAAAAAAAAA CN=XXXXXXXX
1ygfA1NNNNNNNNNNNN CN=XXXXXXXX
I just want to loop through this list and check if Subject Property Contains "*XXXX" value. But the above code is not working.its throwing error saying $certifiacte is not recognized as a cmdlet or script. what i am doing wrong?
Upvotes: 0
Views: 505
Reputation: 428
This can be done in a much less complicated looking fashion in a single line:
If (Get-ChildItem Cert:\LocalMachine\My\ | Where-Object {$_.Subject -like CN=*XXXX}) {"Cert installed."}
Shortened:
If (Get-ChildItem Cert:\LocalMachine\My\ | ? Subject -like CN=*XXXX) {"Cert installed."}
Upvotes: 1