Looking for explanation on something

Hi there
i have a script that finds the template name of a certificate and it works:

Blockquote
Get-ChildItem ‘Cert:\LocalMachine\My’ | Where-Object{ $.Extensions | Where-Object{ ($.Oid.FriendlyName -eq ‘Certificate Template Information’) -and ($_.Format(0) -match $templateName) }}

im trying to understand what this part does:
$_.Format(0)

thanks

Short answer: it calls the method .Format() with the parameter 0 on the Extensions property of a certificate object.

How can you figure that out by yourself? …

Running …

Get-ChildItem 'Cert:\LocalMachine\My'

… outputs some objects of a certain type. They have some properties and some methods. To inspect it and display these methods and properties you can use Get-Member. And because one object is enough we use the first object the cmdlet returns for the further steps here.

(Get-ChildItem 'Cert:\LocalMachine\My')[0] | 
    Get-Member

The output you get will have pretty likely a property named Extensions. So we use Get-Member again on that property:

(Get-ChildItem 'Cert:\LocalMachine\My')[0].Extensions | 
    Get-Member

This output should have the method .Format() you was looking for.

To figure out what this method exactly does you could try to find a documentation or you simply play around a little bit. :wink:

(Get-ChildItem 'Cert:\LocalMachine\My')[0].Extensions.Format(0)

or

(Get-ChildItem 'Cert:\LocalMachine\My')[0].Extensions.Format(1)

or

(Get-ChildItem 'Cert:\LocalMachine\My')[0].Extensions.Format(2)

Cool? :+1:t4: :love_you_gesture:t4:

yeah i did all that but still couldnt exactly figure out why when i goto .extensions i see bunch of stuff
when i use .format(0) i see stuff that i dont even see in .extensions

Of course. It’s like a closet with drawers with boxes in it. When you open the closet you can see the drawers but not the boxes. You have to open the drawers to access the boxes. And the boxes to access their content. :wink: