This is the powershell script to turn the output of AeXAgentUtil.com into objects in powershell.Sorry about the formatting. The forum does have a code insert for powershell.
#Path to AeXAgentUtil.com
$AexAgentUtilPath="C:\Program Files\Altiris\Altiris Agent\AeXAgentUtil.com"
#Find certs related to SMA
$certs=& $AexAgentUtilPath /findcert
#Add double quotes to each line for data integrity and allows me to see an empty so and use that as a separator
#Then joined all lines as 1 big string
#After that I split each double doublequote, so it separates each certificate in it's own individual line
#I skip the last 3 lines cause they are not needed
$AllCerts=(($certs |ForEach-Object -Process {
"""$_"""
}) -join "#" -split """""") | Select-Object -SkipLast 3
#Remove CertsList if it exists, so this script can be run multiple times
Remove-Variable -Name CertsList
$AllCerts | ForEach-Object -Process {
#Created an array by splitting # and filtering out all the empty lines
#Re-joined it back into a single string
<#
replaced the matched string (, "#" ) so that a location can look correctly from a cert by making it one single line
EG: Note: This is split on 2 lines:
US, New York, New York, Company, Department,
Server.Domain.com,
user@email.com#>
#Replaced matched string (#" ) with (;"), so multiple lines of the same field can be split later
#This will create an array with the individual fields are on it's own line and not on multiple lines
#To look at how the data looks like before formatting, just run $_ -split "#"
$Trimmed=($_ -split "#" | Where-Object -FilterScript {$_ -ne ""}) -join "#" -replace ", ""#"" ",", " -replace "#"" ",";"""
#$Trimmed | Where-Object -FilterScript {
#Splits each field
#Replaces (-replace "^""") the double quotes at the beginning of the string
#Replaces (-replace """$") the double quotes at the end of the string
#Replaces the string (";") with just ;, so it removes the double quotes
$TrimmedSplit=$Trimmed -split "#" -replace "^""" -replace """$" -replace " " -replace """;""",";"
#Creating an array for each certificate
#$TrimmedSplit[index] splits the colon so it is an object
<#
This section removes the field name along with the colon
If the string has a semi-colon, then it means the field has multiple lines
The if statement will split the semi-colon into mutliple lines like how it is seen in the command line version
($TrimmedSplit[1] -replace "^[^:]*:\s*" -split ";" |`
Where-Object -FilterScript {
If ($_ -match ";") {
$_ -split ";"
} else {
$_
}
})
#>
$CertsList+=@(New-Object -TypeName psobject -Property @{
Certificate=$TrimmedSplit[0]
($TrimmedSplit[1] -split ":")[0]=($TrimmedSplit[1] -replace "^[^:]*:\s*" -split ";" |`
Where-Object -FilterScript {
If ($_ -match ";") {
$_ -split ";"
} else {
$_
}
})
($TrimmedSplit[2] -split ":")[0]=($TrimmedSplit[2] -replace "^[^:]*:\s*" -split ";" |`
Where-Object -FilterScript {
If ($_ -match ";") {
$_ -split ";"
} else {
$_
}
})
($TrimmedSplit[3] -split ":")[0]=($TrimmedSplit[3] -replace "^[^:]*:\s*" -split ";" |`
Where-Object -FilterScript {
If ($_ -match ";") {
$_ -split ";"
} else {
$_
}
})
($TrimmedSplit[4] -split ":")[0]=($TrimmedSplit[4] -replace "^[^:]*:\s*" -split ";" |`
Where-Object -FilterScript {
If ($_ -match ";") {
$_ -split ";"
} else {
$_
}
})
($TrimmedSplit[5] -split ":")[0]=($TrimmedSplit[5] -replace "^[^:]*:\s*" -split ";" |`
Where-Object -FilterScript {
If ($_ -match ";") {
$_ -split ";"
} else {
$_
}
})
($TrimmedSplit[6] -split ":")[0]=($TrimmedSplit[6] -replace "^[^:]*:\s*" -split ";" |`
Where-Object -FilterScript {
If ($_ -match ";") {
$_ -split ";"
} else {
$_
}
})
($TrimmedSplit[7] -split ":")[0]=($TrimmedSplit[7] -replace "^[^:]*:\s*" -split ";" |`
Where-Object -FilterScript {
If ($_ -match ";") {
$_ -split ";"
} else {
$_
}
})
($TrimmedSplit[8] -split ":")[0]=($TrimmedSplit[8] -replace "^[^:]*:\s*" -split ";" |`
Where-Object -FilterScript {
If ($_ -match ";") {
$_ -split ";"
} else {
$_
}
})
($TrimmedSplit[9] -split ":")[0]=($TrimmedSplit[9] -replace "^[^:]*:\s*" -split ";" |`
Where-Object -FilterScript {
If ($_ -match ";") {
$_ -split ";"
} else {
$_
}
})
($TrimmedSplit[10] -split ":")[0]=($TrimmedSplit[10] -replace "^[^:]*:\s*" -split ";" |`
Where-Object -FilterScript {
If ($_ -match ";") {
$_ -split ";"
} else {
$_
}
})
($TrimmedSplit[11] -split ":")[0]=($TrimmedSplit[11] -replace "^[^:]*:\s*" -split ";" |`
Where-Object -FilterScript {
If ($_ -match ";") {
$_ -split ";"
} else {
$_
}
})
($TrimmedSplit[12] -split ":")[0]=($TrimmedSplit[12] -replace "^[^:]*:\s*" -split ";" |`
Where-Object -FilterScript {
If ($_ -match ";") {
$_ -split ";"
} else {
$_
}
})
($TrimmedSplit[13] -split ":")[0]=($TrimmedSplit[13] -replace "^[^:]*:\s*" -split ";" |`
Where-Object -FilterScript {
If ($_ -match ";") {
$_ -split ";"
} else {
$_
}
})
})
}