I agree, if I were to spend time updating that script (which, hey, I'm glad you 
are doing so instead!) I wouldn't use capicom, I'd use the Cert: available 
right in powershell.  

Capicom was technically deprecated at the time that original script was 
written; but it was the best (or maybe the easiest method might be a better 
choice of words) way to get the info we wanted at the time.  But yeah, it's 
dated now for sure.

If anyone gets an updated posh script to populate wmi with cert info, please do 
blog it /share it. 


On Wednesday, June 11, 2014 7:59 PM, elsalvoz <[email protected]> wrote:
  


would this work? this creates an array with certs info as hashtable. you can 
manipulate it as you want.
$Certificates = Get-ChildItem -Path cert:\LocalMachine\My
 $g=@()
If ($Certificates.Count -gt 0) 
   {ForEach ($Certificate in $Certificates)
       {
   $strDaysToExpire = (New-TimeSpan -End ([DateTime]$Certificate.NotAfter))
    
        $g += @{
       strSubjectName = $Certificate.SubjectName
       strIssuerName = $Certificate.IssuerName
       strValidFrom = $Certificate.NotBefore
       strValidTo = $Certificate.NotAfter 
       strDaysToExpire = $($strDaysToExpire.days)
        }
         }
         }
 $g 



On Wed, Jun 11, 2014 at 5:09 PM, Robertson, Casey 
<[email protected]> wrote:

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  J 
>  
>$Certificates=Get-ChildItem-Pathcert:\LocalMachine\My 
>  
>If($Certificates.Count-gt0) 
>   {ForEach($Certificatein$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  
>  
>ThanksCasey   
>


Reply via email to