Created
April 24, 2018 01:49
-
-
Save jezzsantos/b8c0524e8ec0c8843e797d23c32a1908 to your computer and use it in GitHub Desktop.
This file contains 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
$resourceGroup = "hourfleet-tenants-ause" | |
$storageAccount = "hourfleettenant1" | |
$tableName = "useraccounts" | |
$saContext = (Get-AzureRmStorageAccount -ResourceGroupName $resourceGroup -Name $storageAccount).Context | |
#Next line is for 'classic' storage accounts | |
#$saContext = (New-AzureStorageContext -StorageAccountName $storageAccount -StorageAccountKey "PUTSTPORAGEACCOUNTKEYHERE").Context | |
$userAccountsTable = Get-AzureStorageTable -Name "useraccounts" -Context $saContext | |
$verificationsTable = Get-AzureStorageTable -Name "verifications" -Context $saContext | |
$userProfilesTable = Get-AzureStorageTable -Name "userprofiles" -Context $saContext | |
$userAccounts = Get-AzureStorageTableRowByCustomFilter -table $userAccountsTable -customFilter "(Roles eq 'clientapplication') or (Roles eq 'partnerapplication')" | |
foreach ($userAccount in ($userAccounts)) | |
{ | |
$accountId = $userAccount.Id | |
$resourceIdFilter = "(ResourceId eq '" + $accountId + "')" | |
$verifications = Get-AzureStorageTableRowByCustomFilter -table $verificationsTable -customFilter $resourceIdFilter | |
$verificationCount = 0 | |
foreach ($verification in ($verifications)) | |
{ | |
$verificationCount = $verificationCount + 1 | |
Remove-AzureStorageTableRow -table $verificationsTable –entity $verification | |
} | |
$accountId + " - Verifications: " + $verificationCount | |
$userProfileIdFilter = "(Id eq '" + $accountId + "')" | |
$userProfiles = Get-AzureStorageTableRowByCustomFilter -table $userProfilesTable -customFilter $userProfileIdFilter | |
$userProfilesCount = 0 | |
foreach ($userProfile in ($userProfiles)) | |
{ | |
$userProfilesCount = $userProfilesCount + 1 | |
Remove-AzureStorageTableRow -table $userProfilesTable –entity $userProfile | |
} | |
$accountId + " - UserProfiles: " + $userProfilesCount | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a reference for automating maintenance tasks in table storage