Python・PowerShellとIntersight API6 / 10

ACIのtenant名を列挙する

APICの/api/node/class/fvTenant.jsonへの応答は、imdataの各要素にfvTenantを持ち、そのattributes.nameがtenant名になる。JSON文字列をConvertFrom-Jsonで変換し、配列をforeachで走査する。

foreach ($item in $resultjson.imdata) {
    Write-Host $item.fvTenant.attributes.name
}

foreachはコレクションの各要素を順に処理するため、返される件数を事前に指定する必要がない。応答がページに分割される要求では、そのページの要素を列挙する処理と、次のページを取得する処理を分ける。

学習パスへ
参考資料