2017-11-21 13 views
0

以下のスクリプトを実行して、VSTS powershellタスクの引数セクションを使用してpowershellスクリプトを通して$ fileObjのスクリプトパラメータを渡しています。Azureにテーブルデータをデプロイしようとしていますテーブルストレージ。私は.csvファイル内にテーブルデータを持っており、これらのテーブルエンティティをpowershellスクリプトを使用してデプロイし、空白のテーブルストレージにデプロイしようとしています。以下のスクリプトは、テーブルエンティティをデプロイするのではなく、エラーで失敗します。誰かが私を助けてくれますか? 私はonedrive場所にエラーログ付属している:あなたの言及ログによるとhttps://onedrive.live.com/?authkey=%21AEh2aAOnbmuzq9U&cid=5599285D52BD31F3&id=5599285D52BD31F3%21900&parId=root&action=locatepowershellスクリプトを使用してテーブルをAzureテーブルストレージにデプロイ中のエラー

foreach($fo in $fileObj){ 
Write-Host $fo.filepath 
$csv = Import-CSV $fo.filepath 
    $cArray=$fo.Cols.split(",") 
    foreach($line in $csv) 
    { 
    Write-Host "$($line.partitionkey), $($line.rowKey)" 
    $entity = New-Object -TypeName Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity -ArgumentList $line.partitionkey, $line.rowKey 
     foreach($c in $cArray){ 
    Write-Host "$c,$($line.$c)" 
$entity.Properties.Add($c,$line.$c) 
} 
$result = $table.CloudTable.Execute([Microsoft.WindowsAzure.Storage.Table.TableOperation]::Insert($entity)) 
} 
} 

$subscriptionName = "" 
$resourceGroupName = "" 
$storageAccountName = "" 
$location = "" 

# Get the storage key for the storage account 
$StorageAccountKey = "" 

# Get a storage context 
$ctx = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageAccountKey 
+0

誰もが私の問題への対応いただけますか? – PRAVEEN

答えて

0

を、私はあなたのCSV列名があなたのコードに対応していないように見えることがわかります。また、PartitionkeyとRowkeyという名前の2つのColunmsを持つCSVファイル形式が正しくありません。次のデモコードとCSVファイル形式を使用してみてください。それはmysideで正しく動作します。

$resourceGroup ="resourceGroup name" 
$storageAccount = "storage account Name" 
$tableName = "table name" 
$storageAccountKey = "storage key" 
$ctx = New-AzureStorageContext -StorageAccountName $storageAccount - 
StorageAccountKey $storageAccountKey 

######### Add removing table and create table code ####### 
try 
{ 
    Write-Host "Start to remove table $tableName, please wait a moment..." 

    Remove-AzureStorageTable -Name $tableName -Context $ctx -Force # Remove the Azure table 

    Start-Sleep -Seconds 60 # waiting for removing table, you could change it according to your table 

    Write-Host "$tableName table has been removed" 
} 
catch 
{ 
    Write-Host "$tableName is not existing" 
} 
Write-Host "Start to create $tableName table" 

New-AzureStorageTable -Name $tableName -Context $ctx # Create new azure storage table 

##########Add removing table and create table code ############ 

$table = Get-AzureStorageTable -Name $tableName -Context $ctx 
$csvPath ='csv file path' 
$cols = "Label_Usage,Label_Value,Usage_Location" #should be corrensponding to your csv column exclude Partitionkey and RowKey 
$csv = Import-Csv -Path $csvPath 
$number = 0 
[Microsoft.WindowsAzure.Storage.Table.TableBatchOperation]$batchOperation = New-Object -TypeName Microsoft.WindowsAzure.Storage.Table.TableBatchOperation 
foreach($line in $csv) 
{ 
    $number++ 
    $entity = New-Object -TypeName Microsoft.WindowsAzure.Storage.Table.DynamicTableEntity -ArgumentList $line.partitionkey, $line.rowKey 
    $colArray = $cols.split(",") 
    Write-Host "$($line.partitionkey), $($line.rowKey)" #output partitionkey and rowKey value 
    foreach($colName in $colArray) 
    { 
     Write-Host "$colName,$($line.$colName)" #output column name and value 
     $entity.Properties.Add($colName,$line.$colName) 
    } 
    if($number -le 100) 
    { 
     $batchOperation.InsertOrReplace($entity) # Changed code 
    } 
    else 
    { $number =0 
     $result = $table.CloudTable.ExecuteBatch($batchOperation) 
    [Microsoft.WindowsAzure.Storage.Table.TableBatchOperation]$batchOperation = New-Object -TypeName Microsoft.WindowsAzure.Storage.Table.TableBatchOperation 
    } 
} 
if($batchOperation.Count -ne 0) 
{ 
$result = $table.CloudTable.ExecuteBatch($batchOperation) 
} 

注:バッチ操作のためにでCSVファイルと同じパーティションキー値のレコードが必要です。


CSVファイルフォーマット例

enter image description here

試験結果:

enter image description here

+0

、この問題にお返事いただきありがとうございます。私が人々を助けてくれるのを待っています。エラーログファイル@ https://1drv.ms/t/s!AvMxvVJdKJlVhw-m9I5DmLRSpYFAを共有しました。エラーを確認してください私を助けてください。私はまだ間違いに直面しています。 – PRAVEEN

+0

更新@トム。 – PRAVEEN

+0

あなたによると、[Azure Table Batch Operation Limit](https://docs.microsoft.com/en-us/dotnet/api/microsoft.windowsazure.storage.table.tablebatchoperation?view=azure-ドットネット)。 'バッチ操作は、100個までの個々のテーブル操作を含むことができ、各操作エンティティは同じパーティションキーを持つ必要があります。リトリーブ操作を含むバッチには、他の操作を含めることはできません。バッチ処理の合計ペイロードは4MBに制限されています。 –

関連する問題