Forum Discussion

robmo's avatar
robmo
Brass Contributor
Feb 15, 2023

Custom detection method using PowerShell

Hi,

I need a detection method for a specific certificate installed. The script that installs the certificate is working properly but I cannot get the detection method to reflect whether the package needs to run or not. When I run the detection method script manually, it is working the way it should. Line 11 has been verified to return an Int32 by using GetType(). Here is the script being used:

 

 

#Serial number of certificate
$sn = "7653feac75464893f5e5d74a483a4ef8"
#Certificate store where the cert will be added
$storeName = "Root"
 
#Open the certificate store for reading
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store $storeName, LocalMachine
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadOnly)
 
#Check if the certificate is installed
$certFound = (@( ($store.Certificates | Where-Object {$_.SerialNumber -eq $sn}) ).count)
 
#Close the certificate store
$store.Close()

#Return the status of the certificate installation
if($certFound -ge 1) {
    #The certificate is installed
    Exit 0
} else {
    #The certificate is not installed
    Exit 1
}

 

 

The behavior I am seeing is if the certificate is installed, the package appears on the Applications tab of Software Center. If the certificate is not installed, the package is not appearing on the Applications or Installation status tabs. It's simply not available in Software Center.

 

Thank you!

Rob

  • We decided to use group policy to expedite the deployment of the certificate. It was taking too much time to come up with a working powershell solution.

Resources