Just a little varning.
Capicom is depricated by MS so if you want a more future secure way you should 
be looking into the .NET API:s for certificate management or you can just use 
certutil.exe and wrap that in a script

I have some code posted for that on Johans blog. (It was about doing 801.X with 
SCCM2012 but it do use certutil wrapping)
/Mats

Från: [email protected] [mailto:[email protected]] 
För Robertson, Casey
Skickat: den 12 juni 2014 02:10
Till: [email protected]
Ämne: [mssms] Very rusty with scripting and doing custom inventory

Stepped away from SCCM for a while but used to leverage VBscripts all the time 
to query various things and drop them into WMI.  Now that I'm back in the SCCM 
world I'd like to do this again but with PowerShell.  Having a devil of a time. 
 I found Sherry and Matthew's script here:

http://www.sccm-tools.com/tools/vbscript/vbscript-certificates.html

I wanted to convert it to Powershell but I'm striking out on the initial array. 
 This is the code in VBScript:


Store.Open CAPICOM_LOCAL_MACHINE_STORE, "MY" ,CAPICOM_STORE_OPEN_READ_ONLY

Set Certificates = Store.Certificates

If Certificates.Count >0 Then
   For Each Certificate in Certificates
       g=g+1
       strSubjectName(g) = Certificate.SubjectName
       strIssuerName(g) = Certificate.IssuerName
       strValidFrom(g) = Certificate.ValidFromDate
       strValidTo(g) = Certificate.ValidToDate
       strDaysToExpire(g) = DateDiff("d",now(),Certificate.ValidToDate)


This is how I'm trying to do it in Powershell but I keep getting an error about 
"Cannot index into a null array".  Any help?  Sorry for being a poor scripter  
:)

$Certificates = Get-ChildItem -Path cert:\LocalMachine\My

If ($Certificates.Count -gt 0)
   {ForEach ($Certificate in $Certificates)
       {
        $g++
       $strSubjectName[$g] = $Certificate.SubjectName
       $strIssuerName[$g] = $Certificate.IssuerName
       $strValidFrom[$g] = $Certificate.NotBefore
       $strValidTo[$g] = $Certificate.NotAfter
       $strDaysToExpire[$g] = New-TimeSpan -End 
([DateTime]$Certificate.NotAfter)
         $strDaysToExpire[$g] = $($strDaysToExpire.days)

         }
         }

Script probably has other issues too but one step at a time

Thanks
Casey




Reply via email to