$clientid = "アプリケーション(クライアント)ID" $clientsecret = "クライアントシークレットの値" $subscriptionid = "サブスクリプションID" $tenantid = "テナントID" resource = "https://management.azure.com/" $tokenendpoint = "https://login.microsoftonline.com/$tenantid/oauth2/token" $body = @{ grant_type = "client_credentials" resource = $resource client_id = $clientid client_secret = $clientsecret } $tokenresponse = Invoke-RestMethod -Method Post -Uri $tokenendpoint -Body $body -ContentType "application/x-www-form-urlencoded" $accesstoken = $tokenresponse.access_token $headers = @{ 'Authorization' = "Bearer $accesstoken" 'Content-Type' = 'application/json' } $dateEnd = "2025-01-12" #請求期間最終日の翌日 $bullingPeriodCurrentStart = "2024-12-12" #請求期間開始日 $dateStart = $bullingPeriodCurrentStart + "T00:00:00.0000000Z" $bullingPeriod = "202501" #請求期間(YYYYMM) $requesturi = "https://management.azure.com/subscriptions/$subscriptionid/providers/Microsoft.Billing/billingPeriods/$bullingPeriod/providers/Microsoft.Consumption/usageDetails?api-version=2019-01-01&$filter=properties/usageStart ge '$dateStart' and properties/usageEnd lt '$dateEnd'" $ret = (Invoke-RestMethod -Uri $requesturi -Headers $headers -Method Get) $ret.value.properties |Export-Csv .\202501.csv #CSVファイルのパス start .\202501.csv #CSVファイルのパス