Need to build list of computer certificates:

Hi,
I am new to the world of Powershell scripting and need some assistance from you guys,
Basically I need to build a list of certificates against a text file of all machines in my domain but also need to list only certificates with keywords within the issuer property.
I am using a -like filter but can seem to only use one of these within my line of code as below…

Import-module pki
cd cert:\localmachine
Get-ChildItem -recurse | select -property PSParentPath, version, SerialNumber, Issuer, subject, notbefore, notafter | where-object -Property issuer -like "*ABC*"

Can anyone tell me what I need to do to add an additional -like value in the same line of code if possible?

Many thanks in advance!

Try using the FilterScript parameter in your Where-Object.

Get-ChildItem -recurse | select -property PSParentPath, version, SerialNumber, Issuer, subject, notbefore, notafter | where-object -FilterScript {$PSItem.Issuer -like "*Microsoft*" -and $PSItem.Version -eq 3}

Hi Will, many thanks for your quick reply!

I have tried your suggestion and applied it to my code as below:

 Get-ChildItem -recurse | select -property PSParentPath, version, SerialNumber, Issuer, subjec, notbefore, notafter | where-object -filterscript {$PSItem.issuer -like "**" -and $PSItem.issuer ="**" -and $PSItem.issuer = "**"} 

However, I now receive the error below:

At line:1 char:146

  • … -filterscript {$PSItem.issuer -like “" -and $PSItem.issuer ="” -and …
  •                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

The assignment expression is not valid. The input to an assignment operator must be an object that is able to accept assignments, such
as a variable or a property.
At line:1 char:196

  • … PSItem.issuer ="" -and $PSItem.issuer = ""}
  •                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    

The assignment expression is not valid. The input to an assignment operator must be an object that is able to accept assignments, such
as a variable or a property.
+ CategoryInfo : ParserError: (:slight_smile: [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : InvalidLeftHandSide

Apologies if the full error is a bit overkill here, just trying to be conscise.

Again, many thanks for your help so far.

Hi Will,
Apologies, my code snippet above was incorrect, I have corrected it as below and it runs without error, however it returns no results :frowning:

 Get-ChildItem -recurse | select -property PSParentPath, version, SerialNumber, Issuer, subjec, notbefore, notafter | where-object -filterscript {$PSItem.issuer -like "*STR-1*" -and $PSItem.issuer -like "*STR-2*" -and $PSItem.issuer -like "*STR-3*"} 

Any idea why, is it ok to add similar -like statements in the same filter reference?
Again, thanks for your help so far.

Did you mean -and ??

you are asking $PSItem.issuer to be like STR-1 STR2 and STR3 or with -or

where-object -filterscript {$PSItem.issuer -like “STR-1” -and $PSItem.issuer -like “STR-2” -and $PSItem.issuer -like “STR-3”}

try with -or

Yes, -or was the final solution, may thanks for both of your helps on getting this sorted out for me.
This is my very first posting on any blog and I am so impressed, you guys are worth your weight in gold!

Thanks again :slight_smile:

np anytime

Anytime! :slight_smile: