Home > #kravis, #PowerShell, PowerShell, PowerShell Posts, Technology > PowerShell :- Certificate Object Model Creation Part 1

PowerShell :- Certificate Object Model Creation Part 1

Certificate Object Model Creation Part 1

An object model is a logical interface, software or system that is modeled through the use of object-oriented techniques. It enables the creation of an architectural software or system model prior to development or programming. An object model is part of the object-oriented programming (OOP) lifecycle.
What is an Object Model? – Definition from Techopedia
https://www.techopedia.com/definition/8635/object-model

What I’ve created is a representation, (work in progress) that represents an object model for a certificate using PowerShell and by creating XML that can be loaded into a database further analysis can be performed on results. Using a DTD assists with well-formed XML. I’ve been considering adding MongoDB into the mix and will do so shortly. Currently all certs on my machine(s) can be read and placed into an SQLServer Database.

I’ll start by going over steps and functions to load the certs on a machine into a collection. I’ll begin by loading a function to create to create $global:CertCollection. I used simple method to compress RawData to include a comma separator for that field. I will go over using TypeLib’s to assist with other field values in another post.
Let’s do some pre-setup so the command will run
Import-Module PKI
Set-Location Cert:\LocalMachine

function Build-GlobalCert()
{
##
### Builds collection from under root
## Ran with out ` line continuation all should be on one line.
$global:CertCollection = GET-CHILDITEM –RECURSE | Select-Object -Property “PSPath”,
“PSParentPath”, “PSChildName”, “PSDrive”, “PSProvider”, “PSIsContainer”, “EnhancedKeyUsageList”, “DnsNameList”,
“SendAsTrustedIssuer”, “EnrollmentPolicyEndPoint”, “EnrollmentServerEndPoint”, “PolicyId”, “Archived”, “Extensions”, “FriendlyName”, “IssuerName”,
“NotAfter”, “NotBefore”, “HasPrivateKey”, “PrivateKey”, “PublicKey”, “SerialNumber”, “SubjectName”, “SignatureAlgorithm”, “Thumbprint”, “Version”, “Handle”, “Issuer”,
“Subject”, @{ Name = “RawData”; Expression = { ([string]::Join(“,”, $_.RawData)) } }
}
##Call or run your function:
Build-GlobalCert

And that generates the collection we can work with running $global:certcollection returns all items in the collection.
$global:certcollection[$global:certcollection.count-1] entering this command displays the last record contained in the collection.

If you’re working from command line and don’t want to type full item each time you can shorten into a single variable.
$lastCert = $global:certcollection[$global:certcollection.count-1]
$lastcert
lastcertincollection

By looking at the output I decided to create the XML following the pattern the output revealed.
Using a simple tool like XMLNotePad from Microsoft will allow you to quickly work on xml for an object model representation using XML.
It’s a free tool and you don’t require much to understand the concept. Search msdn.com and you should find it.

certobjectmodelxmlcoll

In my next post I’ll start the drill down process into the collection to build the XML/Object Model
Next post is Certificate Object Model Creation Part 2

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: