$global:cert_id_file = "C:\Users\Administrator\Desktop\test1.csv" $global:customer_url = "venafitest" $global:sectigo_api_url = "https://hard.cert-manager.com/api/ssl/v1" #$global:sectigo_api_url = "https://cert-manager.com/api/ssl/v1" #$global:log = "C:\Users\Administrator\Desktop\log.txt" <################################################################################################## .NAME Import-Certificates .DESCRIPTION Imports certificates from Sectigo into the Trust Protection Platform .PARAMETER General A hashtable containing the general set of variables needed by all or most functions UserName: the username required to authenticate with the CA UserPass: the password required to authenticate with the CA .PARAMETER Specific A hashtable containing the specific set of variables needed by this function CustomFields: the list of custom fields defined in the Trust Protection Platform .NOTES Returns a hashtable that includes the following variables Result: 'Success' or 'NotUsed' to indicate the non-error completion state Certificates: An array of hashtables containing certificate/key data CustomName: Sets the name of certificate object in Policy tree ContactEmail: Contact e-mail address for the certificate - if local or AD/LDAP lookup does not find such an identity the assigned value will be assigned to the Internet Email Address attribute TransactionId: Id of the CA Transaction Name: PEM file name PEM: PEM file content or PKCS#12 Base64 content Password: Encryption password used to decrypt keys and PKCS#12 content RevocationDate: Certificate revocation date Attributes: A hashtable of attributes applicable to the Trust Protection Platform Certificate object CustomFields: A hashtable of Custom Fields values (defined in the Trust Protection Platform), which will be assigned to the Certificate object ##################################################################################################> [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 $ErrorActionPreference = "STOP" function Import-Certificates { Param( [Parameter(Mandatory=$true,HelpMessage="General Parameters")] [System.Collections.Hashtable]$General, [Parameter(Mandatory=$true,HelpMessage="Function Specific Parameters")] [System.Collections.Hashtable]$Specific ) $csv = Import-Csv -Path $global:cert_id_file $certificates = @() $customFields = $Specific.CustomFields foreach ($line in $csv) { if ($line.Status -eq "Revoked" -or $line.Status -eq "Expired" -or $line.Status -eq "Requested") { continue } $username = $General.UserName $password = $General.UserPass $collect_pem_api = "{0}/collect/{1}/x509CO" -f $global:sectigo_api_url,$line.Id $headers = @{ "customerUri" = $global:customer_url; "login" = $username; "password" = $password } $result = Invoke-RestMethod -Method Get -Uri $collect_pem_api -Headers $headers $certCustomFields = $null if ($customFields -ne $null -and $customFields.Count -gt 0) { $certCustomFields = New-Object System.Collections.Hashtable # Add custom fields values #$certCustomFields["CustomField1"] = "Value1" #$certCustomFields["CustomField2"] = "Value2" } $certificates += @{ Name={0} -f $line.Id; PEM=[String]$result; TransactionId={0} -f $line.Id; Attributes=@{}; CustomFields=[System.Collections.Hashtable]$certCustomFields; } } return @{Result="Success"; Certificates=$certificates} }