Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

When I'm executing the script nothing is logging into Test.json.

Can any one tell me how to call function from where-object in inline query?

function getDateOfTimeStamp($dateString) {
    [string[]] $format = @("MM/d/yyyy hh:mm:ss tt", "M/d/yyyy hh:mm:ss tt", "MM/dd/yyyy hh:mm:ss tt", "M/dd/yyyy hh:mm:ss tt")
    $result = $null
    $format.ForEach( { [DateTime] $dt = New-Object DateTime; if ([datetime]::TryParseExact($dateString, $_, [System.Globalization.CultureInfo]::InvariantCulture, [System.Globalization.DateTimeStyles]::None, [ref] $dt)) { $result = $dt } })
    $result
}
$storageaccount = Get-AzureRmStorageAccount -StorageAccountName test123 -ResourceGroupName testinggroup
$table = Get-AzureStorageTable -Name testtable123
$query = New-Object Microsoft.WindowsAzure.Storage.Table.TableQuery
$data = $table.CloudTable.ExecuteQuery($query)       
$data | % { EntityToObject $_ } | Select-Object PartitionKey, RowKey, DateModified| Where-Object {getDateOfTimeStamp DateModified -lt ((Get-Date).ToUniversalTime().AddDays(-10))} | ConvertTo-Json | Out-File "C:\Test.json"
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
247 views
Welcome To Ask or Share your Answers For Others

1 Answer

As Mathias R. Jessen said, you need modify getDateOfTimeStamp DateModified to getDateOfTimeStamp $_.DateModified

How can we delete the rows based on above condtions from table.

You could use Remove-AzureStorageTableRow to delete the rows that selected.

On your scenario, you could try below:

$removedata=$data | % { EntityToObject $_ } | Select-Object PartitionKey, RowKey, DateModified| Where-Object {getDateOfTimeStamp DateModified -lt ((Get-Date).ToUniversalTime().AddDays(-10))}
$removedata|Remove-AzureStorageTableRow -table $table

I like following script to delete 10 days before rows in a table.

$rgname=""
$storagename=""
$tablename=""
$saContext = (Get-AzureRmStorageAccount -StorageAccountName $storagename -ResourceGroupName $rgname).Context
$table = Get-AzureStorageTable -Name $tablename -Context $saContext
$query = New-Object Microsoft.WindowsAzure.Storage.Table.TableQuery
$data = $table.CloudTable.ExecuteQuery($query)    
$remove=$data  | Select-Object PartitionKey, RowKey, TimeStamp| Where-Object {$_.TimeStamp -lt ((Get-Date).ToUniversalTime().AddDays(-10))} 
$removedata|Remove-AzureStorageTableRow -table $table

More information about this please refer to this blog:Working with Azure Storage Tables from PowerShell.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...