#### Parse Certificate Chain #### function ParsCertificateChain($path) { $readFile = [System.IO.File]::OpenText($path) $certificateHash = New-Object System.Collections.ArrayList $BEGIN = "-----BEGIN CERTIFICATE-----" $END = "-----END CERTIFICATE-----" [bool]$read = $false While(!$readFile.EndOfStream) { $line = $readFile.ReadLine() IF($line -match $BEGIN) { $read = $true $hash = $null While($read) { $line = $readFile.ReadLine() IF($line -notmatch $END) { $hash = $hash + $line } ELSE { $read = $false $certificateHash.Add($hash) } } } } $readFile.Close() return $certificateHash } ################# MAIN ################# $path = # Certificate chain path $certificates = New-Object System.Collections.ArrayList $certificates = ParsCertificateChain($path) For ([int] $i = 3; $i -lt $certificates.Count; $i = $i + 1 ) { IF($i -eq '3') { $isLeaf = 'true' $isRoot = 'false' } ELSEIF($i -eq $certificates.Count-1) { $isLeaf = 'false' $isRoot = 'true' } ELSE { $isLeaf = 'false' $isRoot = 'false' } $hostBasedSetupRef = $wsmanConnectionObject.NewReference("SELECT * FROM IPS_HostBasedSetupService WHERE Name='Intel(r) AMT Host Based Setup Service'") $inputObject = $hostBasedSetupRef.CreateMethodInput("AddNextCertInChain") $inputObject.SetProperty("NextCertificate", $certificates[$i]) $inputObject.SetProperty("IsLeafCertificate", $isLeaf) $inputObject.SetProperty("IsRootCertificate", $isRoot) $outputObject = $hostBasedSetupRef.InvokeMethod($inputObject) $returnValue = $outputObject.GetProperty("ReturnValue") }