53 lines
2.1 KiB
PowerShell
53 lines
2.1 KiB
PowerShell
function Get-CertificateInventory {
|
|
<#
|
|
.SYNOPSIS
|
|
Returns an OrderedDictionary that Represents the Certificate Inventory.
|
|
#>
|
|
|
|
[CmdletBinding()]
|
|
Param()
|
|
|
|
$logLead = (Get-LogLeadName);
|
|
$providerStopWatch = [System.Diagnostics.StopWatch]::StartNew()
|
|
|
|
$certDictionary = New-Object System.Collections.Specialized.OrderedDictionary
|
|
$storeDictionary = New-Object System.Collections.Specialized.OrderedDictionary
|
|
|
|
try {
|
|
|
|
Write-Verbose "$logLead : [$($providerStopWatch.Elapsed)] : Getting Machine Certificates"
|
|
$personalCerts = Get-ChildItem -Path Cert:\LocalMachine\My
|
|
$iaCerts = Get-ChildItem -Path Cert:\LocalMachine\CA
|
|
$rootCerts = Get-ChildItem -Path Cert:\LocalMachine\Root
|
|
$trustedPeopleCerts = Get-ChildItem -Path Cert:\LocalMachine\TrustedPeople
|
|
Write-Verbose "$logLead : [$($providerStopWatch.Elapsed)] : Machine Certificates Received"
|
|
|
|
Write-Verbose "$logLead : [$($providerStopWatch.Elapsed)] : Working on Personal Certs"
|
|
$personalCertDictionary = Add-CertificatesToInventoryDictionary $personalCerts
|
|
|
|
Write-Verbose "$logLead : [$($providerStopWatch.Elapsed)] : Working on IA Certs"
|
|
$iaCertDictionary = Add-CertificatesToInventoryDictionary $iaCerts
|
|
|
|
Write-Verbose "$logLead : [$($providerStopWatch.Elapsed)] : Working on Root Certs"
|
|
$rootCertDictionary = Add-CertificatesToInventoryDictionary $rootCerts
|
|
|
|
Write-Verbose "$logLead : [$($providerStopWatch.Elapsed)] : Working on Trusted People Certs"
|
|
$trustedPeopleCertDictionary = Add-CertificatesToInventoryDictionary $trustedPeopleCerts
|
|
|
|
$storeDictionary.Add("Personal", $personalCertDictionary)
|
|
$storeDictionary.Add("IA", $iaCertDictionary)
|
|
$storeDictionary.Add("Root", $rootCertDictionary)
|
|
$storeDictionary.Add("TrustedPeople", $trustedPeopleCertDictionary)
|
|
}
|
|
catch {
|
|
|
|
$storeDictionary["Error"] = $_.Exception.ToString()
|
|
}
|
|
|
|
$certDictionary.Add("Certificates", $storeDictionary)
|
|
|
|
Write-Verbose "$logLead : [$($providerStopWatch.Elapsed)] : Provider Complete"
|
|
$providerStopWatch.Stop()
|
|
|
|
return $certDictionary
|
|
} |