In April this year I’ve posted a script to delete your backup files from Windows Azure Storage.
This week, I’ve got a question from Mark, how you could use this script in a SQL Agent Job on an Azure VM. I mentioned in my previous blog post that you should download the Azure PowerShell cmdlets before you could use the script. But Mark always got the following error when he was trying to download the installation file.
In this blog post I will explain more into detail how you can configure the script correctly in a SQL Server Agent job and how you should install the Azure Powershell Cmdlets.
Startup your VM on Azure and connect to the instance with the SSMS.
Before we install anything extra on the VM, let’s configure a job with the Removal Script that you can find in my previous post. Don’t forget to change the storage account, the access key and the container in the script into your configuration.
Your job step should look like this. Choose the Type=Powershell and not T-SQL.
When you execute the job manually, you will probably get the following error message The term ‘New-AzureStorageContext’ is not recognized as the name of a cmdlet…
This is because we didn’t install the Azure PowerShell cmdlets yet. You can download the cmdlets here. Now, when you try to download this on the Azure VM, you will get the following error:
This is because your browser settings don’t allow you to download files. To fix this, open your Internet Explorer settings and select Internet Options
Select the security tab and click the button Custom level
Scroll down to Downloads and select the option Enable under “File download”
Click OK, close the settings and restart your browser. Now you should be able to download the file to install the Azure PowerShell Cmdlets
Save it and Run the file
First of all you will get this nice welcome screen…
Wait until it is finished and you see the next screen.
Just click Install
You will see that it will install the Microsoft Azure Powershell. Click “I accept” in the next screen
…and wait till the installation is finished
Click finish at the end
In the final screen you should actually see that the Azure Powershell Cmdlets are installed
Ok… that’s it!!!
Go back to the SQL Agent Job and execute it again. Normally the job should execute successfully!
To be 100% sure that it’s working, go to the Management portal of Windows Azure and verify the container if the files have been removed.
Have fun with it!