Copying settings to an Azure Website

The Software as a Service (SaaS) website that I work on has been sold to lots of clients now. Which is great news.

2275.app-1However the more Azure websites we have, the more websites we have to administer, especially if like us you take advantage of Traffic Manager which requires multiple website in different regions. Azure has some great options for making this administration easier. One job is adding all the settings onto the Azure portal, so far I have been manually adding these, but a quicker way is to use powershell.

PowerShell

PowerShell is everywhere these days. You can use it to control Servers, Active Directory and Exchange. So it is no surprise that you can use it to control Azure.

Open a powershell window and run the following command.

Get-AzurePublishSettingsFile

This command opens an IE window which you can login to Azure and download a file which contains settings that Azure can use. Save the *.publishsettings file and run the following command.

Import-AzurePublishSettingsFile “C:\MyPublishSettings\mysubscriptions.publishsettings”

This imports your Azure settings so that PowerShell can do clever things.

Select-AzureSubscription -Default “mysubscription”

This selects which of your Azure subscriptions to use. Now run the following to import settings into PowerShell.

$s = @{“DebugEmailAccount”=”test@example.com”;”SiteWarningBannerText”=””}

And finally run the following to import this settings into the Azure website you specified.

Set-AzureWebsite azure-websitename -AppSettings $s

Sounds easy doesn’t it. Well it is. The hardest part is getting the settings in the correct format to be imported but this is only string manipulation.

For my project I already have a build script which populates a settings.config file with all these settings, so I have just duplicated this to create a settings.config.importtoAzure file. Next time I have a website to create, I can create it on Azure and run the above script, pasting in the settings file that my build has already produced for me.

This only scratches the surface of what you can do with Azure and PowerShell, hopefully I will do far more in the future.

Tidying my desktop

My desktop is always a mess. I constantly download files there and forget all about them.

Every now and then I copy files into sub directories so my desktop looks sane for a day or two before it gets out of control again.

Why don’t I write a script that I can schedule to do this for me. Then my desktop will always be tidy.

I have written a few simple batch scripts, but of course the best scripting language out there at the moment is PowerShell. Lets use that.

Windows provides a nice little utility for writing scripts called the Windows PowerShell ISE, so lets start by loading that up.

PS has lots of help included to help you, just run Get-Help [name of ps command]

To move files you can use Move-Item which works very similar to copy, specify source and destination. In my case I moved files based on their file extension.

Move-Item *.pdf folder

Now all I need to do is schedule this script to run either every day or so, or maybe every time I login or switch my computer on.

PowerShell can do lots more interesting things which hopefully I will blog about soon.

Laziness

I am lazy, I won’t try and deny that. When my alarm goes off in the morning, I will snooze it for twenty minutes or so before getting out of bed.

bill-gates-quoteIn my work my laziness continues. Remote Desktop (or RDP) is probably my number one laziness tool. For those that don’t know RDP allows you to connect to another computer and access it like you were sat in front of it. So I can be sat at my desk and RDP into any other computer in the office including any server. However this laziness tool does sometimes require a bit of effort sometimes, powering on the target computer, logging on locally, making sure the user account you are using is allowed to use RDP.

Writing a script is another example of a laziness tool. I often get asked to do tedious and long-winded task, because I am lazy I will go out of my way to learn how to write a script to do this, so that I can run this script and do this long-winded task in a matter of seconds. There are loads of different types of scripts from database SQL scripts, to PowerShell scripts that can do almost anything on your server.

PowerShell is something Microsoft are really pushing at the moment, you can even write scripts to create new user accounts, so no longer will you have to remember to tick that tickbox for every new user account. And because PowerShell is part of almost all MS technologies you can link Exchange to Active Directory and you don’t even have to remember the right syntax as PowerShell has a built-in help command to tell you how to run that useful command.

As I am now moving into a more developer role can I continue to be lazy? I sure can. Code should be written once and reused as often as possible and this is one of the features of OOP (Object Oriented Programming).

It can be as simple as creating a master page so you don’t need to recreate the same code on every one of your webpages. Or every time you find yourself rewriting the same code again, you plug it into a method so it can be called again and again.

But of course the ultimate way to be lazy is of course get yourself some staff and spend all day getting them to do everything. If you are lucky they may even try and adopt some of these lazy ideas.