The end goal here is to get the x64.msi download link based on the latest version of the Nessus Agent. I need a way to get the first Key with "Nessus Agent" string match and then iterate all objects below until a match is found for the value in the file parameter.
Note, the ""Nessus Agents - 8.2.4" is dynamic as the version number will change over time so this key value cannot be hard coded.
I am new to Powershell and can't find any examples on how to do this, any help would be great! :)
example JSON object below:
{
"releases":{
"latest":{
"Plugins Archive":[
{
"file":"Agent_plugins_expires_2021-05-23.tgz",
"version":"null",
"size":585141662,
"release_date":"05/19/2021",
"product_release_date":"05/19/2021",
"md5":"d001d04decd3ddc0689590c24cd70b4f",
"sha256":"a642b52c428b9ffd7214a76de65a895b2b1b863a9156223e7a80561c1538e766",
"file_url":"https://www.tenable.com/downloads/api/v2/pages/nessus-agents/files/Agent_plugins_expires_latest.tgz"
}
],
"Nessus Agents - 8.2.4":[
{
"file":"NessusAgent-8.2.4-amzn.x86_64.rpm",
"version":"8.2.4",
"size":17067122,
"release_date":"03/31/2021",
"product_release_date":"04/08/2021",
"md5":"00f3d1be5355f256621f9b1241cf0c05",
"sha256":"5c6c3478e35296331e971278eabeaf693c3691f1ebf734adcae3cfbf6c6c23fa",
"file_url":"https://www.tenable.com/downloads/api/v2/pages/nessus-agents/files/NessusAgent-latest-amzn.x86_64.rpm"
},
{
"file":"NessusAgent-8.2.4-debian6_amd64.deb",
"version":"8.2.4",
"size":16824112,
"release_date":"03/31/2021",
"product_release_date":"04/08/2021",
"md5":"c888f6e4ab60b4a2bd85f0b291d44171",
"sha256":"c3655308cb3adbd1319a6eb77210c4eb2c031f5d2288d9affbc103ea0939f220",
"file_url":"https://www.tenable.com/downloads/api/v2/pages/nessus-agents/files/NessusAgent-latest-debian6_amd64.deb"
},
{
"file":"NessusAgent-8.2.4-es5.x86_64.rpm",
"version":"8.2.4",
"size":19471101,
"release_date":"03/31/2021",
"product_release_date":"04/08/2021",
"md5":"c72ca4c47b44067204e394c6d131bb7b",
"sha256":"06f70cf0fbd5d0622367042550d24c48545f61ea7f0856532ae2efa70475a06f",
"file_url":"https://www.tenable.com/downloads/api/v2/pages/nessus-agents/files/NessusAgent-latest-es5.x86_64.rpm"
},
{
"file":"NessusAgent-8.2.4-es6.x86_64.rpm",
"version":"8.2.4",
"size":19407452,
"release_date":"03/31/2021",
"product_release_date":"04/08/2021",
"md5":"3b87ee638758201570adf66cbc369b67",
"sha256":"56e7c130c38d915332093a287cdab39d402777b69f39afd7e1f476423b477af1",
"file_url":"https://www.tenable.com/downloads/api/v2/pages/nessus-agents/files/NessusAgent-latest-es6.x86_64.rpm"
},
{
"file":"nessus-agent-updates-8.2.4.tar.gz",
"version":"8.2.4",
"size":590396412,
"release_date":"03/31/2021",
"product_release_date":"04/08/2021",
"md5":"4348bcf458acfb826c447ff8b5176057",
"sha256":"0130b16ad01d9e189faaf8f51a9ebf824da69977d39b58e50460a24d2dc480a6",
"file_url":"https://www.tenable.com/downloads/api/v2/pages/nessus-agents/files/nessus-agent-updates-latest.tar.gz"
}
My code starts with:
$output = "C:\nessus_releases.json";
$jout = Get-Content -Path $output -raw | ConvertFrom-Json;
As a test, if I run the following, it does return the second object under the "Nessus-Agents - 8.2.4" key:
Write-Output($jout.releases.latest.'Nessus Agents - 8.2.4'.Item(1));
However, trying things like the below to get the key values, doesn't return anything:
$jout.releases.latest | ForEach-Object {
Write-Output($_.key);
};
Also tried the below that again, doesn't return anything:
$version = $jout.releases.latest | Where-Object {$_ -match "Nessus Agents"}
Write-Output($version)
UPDATE:
I think I have a way which seems to work to get the key name:
$properties = $jout.releases.latest |
Get-Member -MemberType Properties |
Select-Object -ExpandProperty Name
$version = $properties | Where-Object {$_ -match "Nessus Agents"}
Write-Output($version)
This returns:
Nessus Agents - 8.2.4
$jout.releases.latest | ForEach-Object { Write-Output($_.key); }also tried:$keys = $jout.releases.keys foreach ($key in $keys) { Write-Output($json[$key]) }but they return nothing. As a test, just doing the following:Write-Output($jout.releases.latest.'Nessus Agents - 8.2.4'.Item(1))Does return the second agent object. So the data is readable. I just don't know how to get the first key name starting with "Nessus Agents*"$jout = Get-Content -Path $output | ConvertFrom-Json