Target: Fetch a list of installed applications from multiple computers to Azure Table Storage using Invoke-RestMethod.
I am trying to collect information from the computer and put it in a batch lets say 100 rows and then insert it into the table.
Prepared the script based on the https://docs.microsoft.com/en-us/rest/api/storageservices/performing-entity-group-transactions this article.
Error: "Invoke-RestMethod: Bytes to be written to the stream exceed the Content-Length bytes size specified"
Here is the code below
$tableEndpoint = 'https://****.table.core.windows.net/$batch'
$tableName = 'InstalledApplications'
$StorageAccount = "********"
$URI = $tableEndpoint + $tableName + $SAS
$cot =@()
$array1 = Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate -unique
foreach($arr in $array1){
$RequestBody = ConvertTo-Json -InputObject @{
"TagetName"= $arr.DisplayName;
"Message"= $arr.DisplayVersion;
"ComputerName"= $ENV:ComputerName;
"Username"= $ENV:Username;
"BatchName" = "_a1e9d677-b28b-435e-a89e-87e6a768a431";
"Content-Type" = "multipart/mixed; boundary=changeset_8a28b620-b4bb-458c-a177-0959fb14c977"
"PartitionKey"= "$ENV:ComputerName";
"RowKey"= $arr.DisplayName
"TableName" = "InstalledApplication"
}
$cot += $RequestBody
}
$batching = $cot[1..10]
$RequestHeaders = @{
"x-ms-date"=(Get-Date -Format r);
"x-ms-version"="2009-09-19";
"Accept-Charset"="UTF-8";
"DataServiceVersion"="3.0;NetFx";
"MaxDataServiceVersion"="3.0;NetFx";
"Content-Type" = "multipart/mixed; boundary=batch_a1e9d677-b28b-435e-a89e-87e6a768a431"
"Content-Length" = "1323"
"Authorization" = "SharedKeyLite " + $StorageAccount + ":" + $SAS
}
Invoke-RestMethod -Method POST -Uri $tableEndpoint -Headers $RequestHeaders -Body $cot -ContentType "multipart/mixed; boundary=changeset_8a28b620-b4bb-458c-a177-0959fb14c977"
Please let me know why content length exceeds although the returned rows are no more than 60.
