Powershell: Create Web App in Microsoft Azure 1


In The previous article we discussed about Automation: Powershell Script to Create WebJob in Microsoft Azure

<#
.SYNOPSIS
Create Web App in Azure Environment

.DESCRIPTION
This script creates a new Web app in the Azure Environment

.EXAMPLE
.CreateAzureWebSite.ps1 -AzureSubscriptionName “dt – Dev” -WebSiteName “myPSTestWebSite” -Location “West US”
#>

Powershell Script to Create Web App in Microsoft Azure

[CmdletBinding(SupportsShouldProcess = $true)]
param(
# The name of valide Azure Subscription associated with Account
[Parameter(Mandatory = $true)]
[string]$AzureSubscriptionName,

# The webSite Name you want to create
[Parameter(Mandatory = $true)]
[string]$WebSiteName,

# The Azure Data center Location
[Parameter(Mandatory = $true)]
[string]$Location
)

# The script has been tested on Powershell 3.0
Set-StrictMode -Version 3

[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials

# To authenticate through Windows Azure Active Directory and downloads associated subscriptions.
Add-AzureAccount

# To select specific subscription from available subscription “Visual Studio Enterprise with MSDN”
Select-AzureSubscription -SubscriptionName $AzureSubscriptionName

# Check if Windows Azure Powershell is avaiable
if ((Get-Module -ListAvailable Azure) -eq $null)
{
throw “Windows Azure Powershell not found! Please install from http://www.windowsazure.com/en-us/downloads/#cmd-line-tools”
}
else
{
Write-Host “Windows Azure Powershell is available!!!”
}

# Create the website
$website = Get-AzureWebsite | Where-Object {$_.Name -eq $WebSiteName }
if ($website -eq $null)
{
Write-Host “Creating website ‘$WebSiteName’.”
$website = New-AzureWebsite -Name $WebSiteName -Location $Location
Write-Host “Website ‘$WebSiteName’ is created successfully.”
}
else
{
throw “Website already exists.  Please try a different website name.”
}


Leave a comment

Your email address will not be published. Required fields are marked *

One thought on “Powershell: Create Web App in Microsoft Azure