0

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?

1 Answer 1

1

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."}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.