Skip to content

Instantly share code, notes, and snippets.

@jezzsantos
Created April 24, 2018 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jezzsantos/b8c0524e8ec0c8843e797d23c32a1908 to your computer and use it in GitHub Desktop.
Save jezzsantos/b8c0524e8ec0c8843e797d23c32a1908 to your computer and use it in GitHub Desktop.
$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
}
@jezzsantos
Copy link
Author

This is a reference for automating maintenance tasks in table storage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment