2017-11-21 17 views
0

아래 스크립트를 실행하고 VSTS powershell task의 인수 섹션을 사용하여 powershell 스크립트를 통해 $ fileObj의 스크립트 매개 변수를 전달합니다. Azure에 테이블 데이터를 배포하려고합니다. 테이블 스토리지. 나는 .csv 파일에 테이블 데이터를 가지고 있으며, powershell 스크립트를 사용하여 테이블 엔티티를 전개하고 하늘색 테이블 스토리지로 배치하려고합니다. 아래 스크립트는 테이블 엔티티를 배치하지 않고 오류로 실패합니다. 아무도 나를 도와주세요. 나는 원 드라이브 위치에 오류 로그 첨부 : 당신의 CSV 열 이름은 코드에 해당되지 않는 것 같습니다 당신의 언급 로그에 따르면 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

, 내가 찾을 수 있습니다. 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

@ Tom의 모든 업데이트. – PRAVEEN

+0

당신에 따르면 그것은 [푸른 하늘 일괄 처리 제한] (https://docs.microsoft.com/en-us/dotnet/api/microsoft.windowsazure.storage.table.tablebatchoperation?view=azure- dotnet). '일괄 처리 작업에는 최대 100 개의 개별 테이블 작업이 포함될 수 있으며 각 작업 엔티티에는 동일한 파티션 키가 있어야합니다. 검색 조작이있는 일} 처리는 다른 조작을 포함 할 수 없습니다. 일괄 작업의 총 페이로드는 4MB로 제한됩니다. ' –