Select Page

Cleaning up Azure storage – an ongoing tale

Back to “Azure Grim Reaper” – flagging and deleting unused storage in Azure.

There is no “nice” way to do this – the Azure Metrics help a lot.

Here’s some code that enumerates a list of subscriptions and pulls out storage accounts, transactions over a period of time, count of storage containers, tables and queues – and reads tags.

It’s generic enough for use in most places.

# setup
#import-module az
#import-module az.storage
# creds
#connect-azaccount
#
# set up array of subs


$subs= ‘<subscription ID>’, ‘<subscription ID>’

# today
$nowdate = Get-Date


#initialise output


$stgdata =@()



Write-Host “Enumerating” $subs.count “subscription(s)”


# loop through the subscription(s)


foreach ($subscription in $subs) {
# in subscription, next read the storage accounts
#set context
write-host “Switching to subscription” $subscription
set-azcontext -subscription $subscription |out-null
write-host “enumerating storage accounts”
$stgacclist = get-azstorageaccount
write-host “Total of” $stgacclist.count “storage accounts in subscription” $subscription


# loop through each storage account


foreach ($stgacc in $stgacclist) {
# in storage account, get all storage containers, tables and queues
# stgacc entity has StorageAccountNme and ResourceGroupName and tags


set-azcurrentstorageaccount -Name $stgacc.StorageAccountName -ResourceGroupName $stgacc.ResourceGroupName


write-host “enumerating storage account ” $stgacc.StorageAccountName ” in resource group” $stgacc.ResourceGroupName
write-host “storage containers”
$stgcontainers = get-azstoragecontainer
write-host “table service”
$tblservice = get-azstoragetable
write-host “queue service”
$qservice = get-azstoragequeue



#get transactions


$transactions = Get-AzMetric -ResourceId $stgacc.id -TimeGrain 0.1:00:00 -starttime ((get-date).AddDays(-60)) -endtime (get-date) -MetricNames “Transactions” -WarningAction SilentlyContinue
write-host “60 days of transactions” $(($transactions.Data | Measure-Object -Property total -Sum).sum)


#reset usage array
$lastused = @()


#loop through each blob service container
foreach ($container in $stgcontainers) {
# in blob storage container
write-host “collecting blob storage data”


$lastused += [PSCustomObject]@{
Subscription = $subscription
ResourceGroup = $stgacc.ResourceGroupName
StorageAccount = $stgacc.StorageAccountName
StorageContainer = $container.name
LastModified = $container.lastmodified.Date
Age = ($nowdate – $container.LastModified.Date).Days


}


#let’s find any unmanaged disks in the container
$allblobs = get-azstorageblob -container $container.name
$vhdblobs = $allblobs | Where-Object {$_.BlobType -eq ‘PageBlob’ -and $_.Name.EndsWith(‘.vhd’)}


}


write-host “Total of ” $stgcontainers.count “containers. Minimum age ” ($lastused.Age |Measure -Minimum).minimum “maximum age” ($lastused.Age |Measure -Maximum).maximum


#append to the array


$stgdata += [PSCustomObject]@{
Subscription = $subscription
ResourceGroup = $stgacc.ResourceGroupName
StorageAccount = $stgacc.StorageAccountName
Transactions = $(($transactions.Data | Measure-Object -Property total -Sum).sum)
ContainerCount = $stgcontainers.Count
TableCount = $tblservice.Count
QueueCount = $qservice.Count
AgingMin = ($lastused.Age |Measure -Minimum).minimum
AgingMax = ($lastused.Age |Measure -Maximum).maximum
vhd = $vhdblobs.count
blobs = $allblobs.count


#tag metadata
itowner = $stgacc.tags.itowner
businessowner = $stgacc.tags.businessowner
application =$stgacc.tags.application
costcenter = $stgacc.tags.costcenter


}
}
}
#output to csv


$stgdata | export-csv <somelocation>\storageacc.csv -force -NoTypeInformation

COVID – week 47 – Feb 1 – Feb 7 2021

Weekend – much concern that the Oxford/AstraZeneca vaccine does not provide adequate protection against the “South Africa” variant. Variant breakout is a real challenge. Lockdown, vaccination are really having an effect on the UK rates. (Below, from The Guardian).

image

Hotspots of South Africa variant in the UK.

Weekend update for Washington State from The Seattle Times. Positive case rate is stable and is certainly trending downwards. Vaccine delivery is slow but picking up; almost 9% have first vaccine shot (compare to 18% in the UK).

Friday – UK variant now 6%+ of COVID cases; this is the more transmissible version.

Thursday – Good data from The Seattle Times on vaccine rates across the state, by race and ethnicity. (paywall) “Scarce doses of the COVID-19 vaccine have so far gone disproportionately to white Washington residents, new data from the state Department of Health (DOH) shows.”

Wednesday – Oxford/AstraZeneca vaccine being limited in multiple locations to 18-55; leaving limited choices for over 55, more at risk community.

Tuesday – another “worrying mutation” in the UK. This may be the pattern for the next year – as vaccinations roll out and some immunity builds; watching for mutations that escape.

Monday – travel bans, closed borders contrasted with re-opening and relaxed restrictions. Parts of Washington State move to “phase 2” – which means restaurants can start to re-open at 25% capacity.

The Guardian The Seattle Times
1 Feb here here
2 Feb here here
3 Feb here here
4 Feb here here
5 Feb here here
6 Feb here here
7 Feb here here

https://www.theguardian.com/world/series/coronavirus-live

https://www.seattletimes.com/tag/coronavirus/

COVID – week 46 – Jan 25 – Jan 31 2021

Weekend – more discussion about how the US is somewhat blind to the new mutations and spread.

Weekly look at Washington State from The Seattle Times

Friday – more stories of vaccine restrictions and low numbers of delivery.

Thursday – EU/UK/NI spat over restrictions on vaccine deliveries.

Wednesday – more spread of the South Africa and Kent mutations; borders being closed; travel being stopped.

Tuesday – vaccine production lagging. Demand exceeds capacity.

Monday – Looking back at a year of COVID. First US cases in late January 2020. Watched the documentary 76 Days over the weekend. Today: 100M global cases, vaccines being delivered, wearing a mask is political.

The Guardian The Seattle Times
25 Jan here here
26 Jan here here
27 Jan here here
28 Jan here here
29 Jan here here
30 Jan here here
31 Jan here here

https://www.theguardian.com/world/series/coronavirus-live

https://www.seattletimes.com/tag/coronavirus/

COVID – week 45 – Jan 18 – Jan 24 2021

Weekend – A year since the first case in Washington State. Good write up on Twitter around UK rates, vaccinations and what next.

Weekly update from The Seattle Times, now showing vaccination data. We are still 3 months into the big wave; with concerns that mutations could make this go on for a while.

Friday – much concern about multiple new mutations.

Thursday – California running low on vaccines, last mile of US distribution is becoming an issue. Microsoft, Starbucks working on Washington State support; Amazon offering US wide support.

Wednesday – Inauguration Day. Hopefully a change of perspective and attitude to the pandemic. Meanwhile – record cases and deaths across the globe.

Tuesday – As the US prepares for a transition to President Biden, there is optimism that 100M vaccinations in 100 days, as well as a more competent and open approach to distribution will make a difference.

Monday – Washington State working on new vaccination plans, partners with Microsoft and Starbucks.

The Guardian The Seattle Times
18 Jan here here
19 Jan here here
20 Jan here here
21 Jan here here
22 Jan here here
23 Jan here here
24 Jan here here

https://www.theguardian.com/world/series/coronavirus-live

https://www.seattletimes.com/tag/coronavirus/

COVID – week 44 – Jan 11 – Jan 17 2021

Weekend – much discussion of virus variants – and whether these will evade the current vaccines.

Seattle Times sometimes forgets to “un-paywall” daily updates. Here’s the status from this weekend. Cases are flat; deaths are up, hospitals are still coping. Still nowhere close to being able to re-open.

Friday – Hopefully the UK positive case numbers have peaked; the daily numbers for positive tests and the continued climb in hospitalisation is horrific. “Warp Speed” branding for vaccine production and delivery is being retired. Vaccine delivery in the US is far to slow and seems to be haphazard.

image

Thursday – King County, WA and Washington State investigating safe and equitable methods for mass vaccinations. School gyms, sports facilities, community centers likely to be used. Incoming President Biden announces goal of 100 vaccinations in 100 days.

Wednesday – Second Impeachment moves Covid off the headlines. Vast numbers of cases still in the US. US States being asked to change eligibility for vaccines at short notice. Incoming President Biden building a solid team for Covid response. Still being hampered by lack of coordination.

Tuesday – three coronavirus cases amongst lawmakers from the shelter-in-place at The Capitol last week. Very sad. Washington State cases picked up again – after a dip in reported numbers over New Year.

Monday – many, many cases around the globe. Flu season in the northern hemisphere, new variant with higher transmission, Christmas mingling. Moderna vaccine should give a year of protection; as noted in mid 2020 this is going to lead to an annual flu + covid shot.

The Guardian The Seattle Times
11 Jan here here
12 Jan here here
13 Jan here here
14 Jan here here
15 Jan here here
16 Jan here here
17 Jan here here

https://www.theguardian.com/world/series/coronavirus-live

https://www.seattletimes.com/tag/coronavirus/

COVID – week 43 – Jan 4 – Jan 10 2021

Weekend – More numbers. 46k NHS employees are sick with Covid. 3M cases in the UK, 80k deaths. UK CMO says “restrictions are too lax” – and probably there is a lot of rule bending going on. Washington State planning mass vaccination sites. 20% of England may have had Coronavirus.

New cases in Washington State are relatively flat – but still high. Data as always from The Seattle Times.

Friday – that UK data still going up. US at 4000+ daily deaths for a few days now. That news has been lost in the chaos. London declared a Covid emergency.

image

In April – shock at 5000+ new cases per day, in November – shock at 20k+ new cases per day. Now 60k+…

image

Thursday – vast numbers of UK cases, locally vaccination is slow.

Wednesday – rioting and attempted coup. Big news, and moves the pandemic off the front page.

Tuesday – The Guardian tracker now showing percentage in the UK having had at least once vaccination. Almost 61k new cases in the UK. Daily cases trending downwards in Washington State which is good.

image

Monday – “back to work” and “back to school” with everyone still stuck at home. The first week of the new year – “work week 1” – and the next milestone will be a year of working from home. Vaccines are being slow, England moved to full lockdown again. Vast numbers of new cases in the UK and the US. 350k deaths in the US.

The Guardian The Seattle Times
4 Jan here here
5 Jan here here
6 Jan here here
7 Jan here here
8 Jan here here
9 Jan here here
10 Jan here here

https://www.theguardian.com/world/series/coronavirus-live

https://www.seattletimes.com/tag/coronavirus/