2
votes

Currently I have a system that does backups to an azure storage blob. Within that blob I have a folder for each customers backups. I would like to be able to use powershell/vb to have each folder checked daily to see if there is a new file within the last 48 hours and if not to send am email alerting which folder does not have a backup. I have done very little programming in my life and what I have done was many moons ago. Could someone help me get started? Right now I am able to do a get-azurestorageblob which shows all the files with their directories and the dates but I have no idea how to use that information to do what I want to do. Thank you

Here is a small sample of the azure command when outputted to txt.

Name BlobType Length ContentType LastModified SnapshotTime
---- -------- ------ ----------- ------------ ------------
80500/backup113013... BlockBlob 3135490287 12/1/2013 3:26:39 ...
80500/backup120113... BlockBlob 3133936105 12/2/2013 3:27:03 ...
80500/backup120213... BlockBlob 3137539329 12/3/2013 3:27:18 ...
90407/backup110113... BlockBlob 2484494132 11/2/2013 4:21:14 ...
90407/backup110213... BlockBlob 2484510293 11/3/2013 4:22:00 ...
90407/backup110313... BlockBlob 2484429713 11/4/2013 5:22:10 ...
90407/backup110413... BlockBlob 2484406856 11/5/2013 5:22:46 ...

1

1 Answers

2
votes

For someone who hasn't done a lot of programming you've certainly made it pretty far just figuring out what tools you can use and getting PowerShell with Azure going this far. I think the command you are looking for is this:

Get-AzureStorageBlob -Container yourContainerName | Where-Object { $_.LastModified -lt ((Get-Date).AddHours(-48)) }

One thing to know about PowerShell is almost all output of commands are actually objects. The console just displays them to you in text. What the command above is doing is taking in everything that comes out of the Get-AzureStorageBlob CmdLet you ran and running a check using the Where-Object cmdlet and anything that meets the criteria is then included in the output. In this case I'm using the Get-Date Cmdlet to get the current time, subtracting 48 hours and checking the Last Modified date property. This will output all of the files that have a Last Modified property of greater than 48 hours, which is what I think you are looking for.

Remember that the output of that command is a collection of objects, so you could then create an alert that included their names, etc.

I'd highly suggest picking up PowerShell in Action or watching the Intro to PowerShell course on Pluralsight. They will help a LOT.