Powershell: Create Storage account in Azure

In The previous article we discussed about Automation: Powershell Script to Copy file from a local folder to an Azure blob storage container


<#
.SYNOPSIS
    Create storage account in Azure Environment

.DESCRIPTION

    This script creates a new storage account in a specific subscription

.EXAMPLE

    .\CreateAzureStorageAccount.ps1 -AzureSubscriptionName "Visual Studio Enterprise with MSDN" -StorageAccountName "myStorageName" -Location "West US"
#>
Powershell Script to Create storage account in Microsoft Azure



[CmdletBinding(SupportsShouldProcess = $true)]

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

    # The Storage Account Name you want to create

    [Parameter(Mandatory = $true)]
    [string]$StorageAccountName,

    # 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 storage account if it does not already exist.

$storageAccount = Get-AzureStorageAccount | Where-Object { $_.StorageAccountName -eq $StorageAccountName }
if($storageAccount -eq $null)
{
    Write-Host "Creating storage account '$StorageAccountName'."
    $storage = New-AzureStorageAccount -StorageAccountName $StorageAccountName -Location $Location
}

In the next Article we will discuss about Tutorial to Create a Virtual Machine on Microsoft Azure with Chef (knife-azure plugin)

Labels: , , ,