Created
December 19, 2018 09:47
-
-
Save AsishP/80c866d44d7d12d15d900f125df3c717 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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