D
D
demudrol2017-01-20 18:56:03
PowerShell
demudrol, 2017-01-20 18:56:03

How to pass two variables from a query to PowerShell?

Good day!
There is a script that looks at certificates in a directory and outputs them in JSON:

$certsname = Get-ChildItem -Path Cert:\LocalMachine\AuthRoot | Select FriendlyName,Thumbprint
$idx = 1
write-host "{"
write-host " `"data`":[`n"
foreach ($currentcert in $certsname)
{
    if ($idx -lt $certs.count)
    {
     
        $line= "{ `"{#CERTID}`" : `"" + $currentcert + "`" },"
        write-host $line
    }
    elseif ($idx -ge $certs.count)
    {
    $line= "{ `"{#CERTID}`" : `"" + $currentcert + "`" }"
    write-host $line
    }
    $idx++;
}
write-host
write-host " ]"
write-host "}"

The result is the following:
{
 "data":[

{ "{#CERTID}" : "@{FriendlyName=GeoTrust; Thumbprint=GDSFGDFG32134SADSAD}" },
{ "{#CERTID}" : "@{FriendlyName=DigiCert; Thumbprint=DSAD124DASDA23123}" },
{ "{#CERTID}" : "@{FriendlyName=The USERTrust NetworkT; Thumbprint=FASDF123123FASD3}" }

 ]

I would like to separate FriendlyName and Thumbprint so that it turns out for each certificate
{ "{#CERTID}" : "GDSFGDFG32134SADSAD" }
{ "{#CERT}" : "GeoTrust" }
How can this be done?
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
azarij, 2017-01-20
@demudrol

Is $certs not defined anywhere? maybe you meant $certsname?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question