Hello,
The script below pulls records from Azure billing.
[pre]
$sql = @’
INSERT INTO [dbo].[AzureBilling](
[UsageStart],
[UsageEnd],
[BillingPeriodName],
[InstanceName],
[UsageQuantity],
[BillableQuantity],
[PretaxCost],
[MeterID]
)
VALUES(
‘{0}’,
‘{1}’,
‘{2}’,
‘{3}’,
‘{4}’,
‘{5}’,
‘{6}’,
‘{7}’
)
go
'@
Get-AzConsumptionUsageDetail -BillingPeriodName 202001 -InstanceName STAGING -Top 1 |
ForEach-Object{
$sql -f $.UsageStart,$.UsageEnd,$.BillingPeriodName,$.InstanceName,$.UsageQuantity,$.BillableQuantity,$.PretaxCost,$.MeterId
}
[/pre]
I’m trying to create an insert statement and use the invoke-sqlcmd to load the data. However, it seems to be inserting the index arrays instead of the data.
[pre]
INSERT INTO [dbo].[AzureBilling]( [UsageStart], [UsageEnd], [BillingPeriodName], [InstanceName], [UsageQuantity], [BillableQuantity], [PretaxCost], [MeterID] ) VALUES( '1/1/2020 12:00:00 AM', '1/1/2020 11:59:59 PM', '20200101', 'STAGING', '22.6451612832258', '', '2.81829032873185', '1450c4f7-f8db-4fc' ) go INSERT INTO [dbo].[AzureBilling]( [UsageStart], [UsageEnd], [BillingPeriodName], [InstanceName], [UsageQuantity], [BillableQuantity], [PretaxCost], [MeterID] ) VALUES( '{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}' )
[/pre]
I seen there is a ‘-variable’ option, but unsure how I would use it.
Thanks,
Frank