Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[Reflection.Assembly]::LoadWithPartialName("System.Web.Script.Serialization")
$resourceName = "<Resource Group Name>"
$azureStorage = "<Storage Container Name>"
$azureTable = "<Azure Storage Table>"
$Credential = Get-Credential
function UploadDataToAzureTableStorage {
param (
[Parameter(Mandatory = $true, HelpMessage = 'Please provide the FileName')][ValidateNotNullOrEmpty()][String]$fileName
)
Write-Output "Connecting to Azure Subscription"
Connect-AzureRmAccount -Credential $Credential
Write-Output "Connect to Storage Container"
$storageCont = Get-AzureRmStorageAccount -ResourceGroupName $resourceName -Name $azureStorage
$ctx = $storageCont.Context
Write-Output "Get Office 365 Audit Log Data Table"
$table = Get-AzureStorageTable -Name azureTable -Context $ctx
$partitionKey = "<PartitionKey>"
$date = Get-Date -Format s
$rowKeyPrefix = "Data_" + $date.Replace(":", "")
$JSSerializer = [System.Web.Script.Serialization.JavaScriptSerializer]::new()
$dataJson = (Get-Content -Path $fileName) | Out-String | ConvertFrom-Json;
for ($i = 0; $i -lt $dataJson.Count ; $i++) {
Write-Output $("Adding Row " + $($i + 1))
$hashtable = $JSSerializer.Deserialize(($dataJson[$i] |ConvertTo-Json), 'Hashtable')
$rowKey = $rowKeyPrefix + $i
$null = Add-StorageTableRow -table $table -partitionKey $partitionKey -rowKey ($rowKey) -property $hashtable
}
Disconnect-AzureRmAccount
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.