(For more resources related to this topic, see here.)
Cloud is one of the most popular words in the ICT industry nowadays; we hear it every day, everywhere, and at every occasion. In simple words, cloud computing is the concept of using and delivering computing resources to the end user as a service. A computing resource could be software such as web portals and messaging systems, or hardware such as CPU, memory, network, and storage. It could be hosted internally in a corporate’s data center “Private Cloud” or externally in a vendor’s data center “Public Cloud”.
There are different types of cloud computing:
Popular solution(s): Microsoft Office 365 and Oracle CRM On Demand
Popular solution(s): Microsoft SQL Azure and Google App Engine
Popular solution(s): Microsoft SQL Azure and Amazon Web Services
This article will cover how Windows PowerShell helps in administering, managing, and automating a cloud computing platform such as Microsoft Windows Azure.
We will also cover the following topics:
Windows Azure is a cloud-computing concept that is created by Microsoft. Mainly, Windows Azure provides IaaS and PaaS, so you can think about using it in many scenarios, such as hosting a web application, deploying a centralized data store, building a development and testing environment, or even implementing a disaster recovery (DR) site for your on-premise environment.
Windows Azure comes with a very neat and easy, web-based management interface that allows you to do any task in a few clicks, but unfortunately this interface is a bit limited. For example, you cannot create a couple of virtual machines in one shot; you have to repeat the same steps twice in order to get two virtual machines. The same goes for the rest of the Azure tasks. That is why, Windows Azure provides a powerful scripting environment via Windows PowerShell to make it easier for administrators to automate multiple Azure tasks, such as the provisioning of virtual machines, application deployment, and infrastructure management.
Windows Azure PowerShell is provided with the Windows PowerShell module as part of the Windows Azure Software Development Kit (SDK). In order to install Windows Azure PowerShell:
After installing Windows Azure PowerShell, a module called “Azure” should be available in your system.
In order to use Windows Azure cmdlets in Windows PowerShell, you can either directly launch the Windows Azure PowerShell shortcut to quickly jump into the Windows Azure PowerShell environment or launch the import Windows Azure PowerShell module into your Windows PowerShell session using the following command:
#Import Windows Azure PowerShell module PS> Import-Module Azure
After downloading, installing, and importing the Windows Azure PowerShell, you are just one step away from managing your Windows Azure environment using PowerShell. The last step is connecting to your Windows Azure subscription.
In order to set up your Windows Azure subscription in your PowerShell, you have to import the PublishSettings file that contains your Windows Azure subscription’s unique information, such as the subscription ID, name, service endpoint URL, and certificate thumbprint. This information will be used by PowerShell to reach your Windows Azure environment.
You can get the PublishSettings file easily by using the Get-AzurePublishSettingsFile cmdlet. This cmdlet will take you to the Windows Azure portal. When you enter your credentials, you will be redirected to an instructional page to generate and download your Windows Azure PublishSettings file for your subscription.
#Generate and download the Windows Azure PublishSettings File PS> Get-AzurePublishSettingsFile
Now you should have the publishsettings file called <AzurePublishSettings>.publishSettings that contains your Windows Azure subscription. The next step is to import it to PowerShell in order to define your subscription information into Windows PowerShell. To import the PublishSettings file, use the Import-AzurePublishSettingsFile cmdlet as follows:
#Import Windows Azure PublishSettings File PS> Import-AzurePublishSettingsFile <FileName>.publishsettings
Once the PublishSettings file is imported successfully, Windows PowerShell will set your subscription as a default subscription; so every time you open Windows PowerShell and use Windows Azure cmdlets, it will automatically connect to Windows Azure using the default subscription. In order to show your subscription information, use the Get-AzureSubscription cmdlet.
So at this point, we can say congratulations!! Your Windows PowerShell environment is now ready to manage your Windows Azure.
In this section, we will help you get started with Windows Azure scripting and automation using a set of Windows PowerShell scenarios and examples.
In this scenario, you are a Windows Azure administrator who wants to get the best performance by making sure that any related cloud components associated with a specific cloud service are placed in the same data center, especially when Microsoft has multiple Azure data centers distributed across the United States, Europe, and Asia. So for this purpose, you need to create an “affinity group” in order to group the related components logically. For this, you will use the New-AzureAffinityGroup cmdlet with the following group of parameters:
Use the Get-AzureLocation cmdlet to get the list of available locations.
You can use the following code:
#Create New Azure Affinity Group PS> New-AzureAffinityGroup –Name "ContosoAffinityGroup" –Location
"West US"
In this scenario, you will create an Azure storage account in order to allow your services, applications, and infrastructure to utilize Windows Azure storage. For this purpose, you will use the New-AzureStorageAccount cmdlet with the following group of parameters:
You can use the following code:
#Create New Azure Storage Account PS> New-AzureStorageAccount -StorageAccountName "contoso" -AffinityGroup
"ContosoAffinityGroup"
In this scenario, you will assign a previously created Azure storage account to your Windows Azure subscription in order to make sure that any task created under this subscription will use this storage account by default. For this purpose, you will use the Set-AzureSubscription cmdlet to define the Windows Azure subscription’s settings with the following group of parameters:
You can use the following code:
#Assign Azure storage account to a specific azure subscription PS> Set-AzureSubscription -SubscriptionName <Subscription_Name>
-CurrentStorageAccount "Contoso"
In this scenario, you will create a Windows Azure Cloud Service. A cloud service describes the components of each solution you have on Windows Azure. For example, if you have a web application hosted on a web server (IIS) that connects to a database hosted on a database server (SQL Server), these two components should be called “Cloud Service”. So, cloud service is an essential requirement for any Azure component you want to create on Windows Azure. For this purpose, you will use the New-AzureService cmdlet with the following group of parameters:
You can use the following code:
#Create new Azure Cloud Service PS> New-AzureService -ServiceName "myCloudService" -AffinityGroup
"ContosoAffinityGroup"
In this scenario, you will create a centralized SQL Server database hosted in the cloud, utilizing the SQL Azure capabilities to host your database. So before you create your SQL Server database, you first need to create a SQL Server instance to host this SQL database. For this purpose, you will use the New-AzureSqlDatabaseServer cmdlet with the following group of parameters:
You can use the following code:
#Create new SQL Azure Database Server instance PS> New-AzureSqlDatabaseServer -AdministratorLogin "SherifT"
-AdministratorLoginPassword "P@ssw0rd" -Location "West US"
In this scenario, you will create a SQL Azure database on a previously created SQL Azure database server instance. For this purpose you will use a couple of cmdlets; the first cmdlet is the New-AzureSqlDatabaseServerContext cmdlet that is used to define which server you will connect to, and the second cmdlet is the New-AzureSqlDatabase cmdlet that is used to create the SQL Azure database.
Following are the group of parameters:
You can use the following code:
#Create SQL Azure Database Server Context PS> $context = New-AzureSqlDatabaseServerContext -ServerName <server_Name> #Create new SQL Azure Database PS> New-AzureSqlDatabase –Context $context -DatabaseName "myDatabase"
–Collation SQL_Latin1_General_CP1_CI_AS -Edition "Web" -MaxSizeGB 1
In this scenario, you will create a SQL Azure Database server firewall rule in order to allow communication between your SQL Azure database server and web application that is hosted either somewhere else or on other computers in a specific network range. For this purpose, you will use the New-AzureSqlDatabaseServerFirewallRule cmdlet to define the firewall rule settings for SQL Azure Server.
Following are the group of parameters:
Use 0.0.0.0 for -StartIpAddress and -EndIpAddress to allow communication between SQL Azure and Windows Azure.
You can use the following code:
#Create SQL Azure Database Server Firewall Rule PS> New-AzureSqlDatabaseServerFirewallRule –ServerName <Server_Name>
-RuleName "myIntranet" -StartIpAddress 192.168.1.1 -EndIpAddress
192.168.1.254
In this scenario, you will create a new Windows Azure virtual machine running a Windows operating system using the quick mode. The quick mode allows you to create a new virtual machine with minimal input from your side; it is good for testing purposes. For the purpose of creating a new virtual machine, you will use the New-AzureQuickVM cmdlet with the following group of parameters:
Use the Get-AzureVMImage cmdlet to list all the images available in Windows Azure.
You can use the following code:
#Create new Windows Azure VM – Windows using Quick Mode PS > New-AzureQuickVM –Windows -ServiceName "DatabaseService" -Name
"CAI-DC-03" -ImageName "MSFT__Windows-Server-2012-Datacenter-
201210.01-en.us-30GB.vhd" -Password P@ssw0rd -AffinityGroup
"ContosoAffinityGroup" -AffinityGroup "ContosoAffinityGroup"
In this scenario, you will create a new Windows Azure virtual machine that is running Linux operating system using the quick mode. For the purpose of creating a new virtual machine, you will use the New-AzureQuickVM cmdlet with the following group of parameters:
You can use the following code:
#Create new Windows Azure VM – Linux using Quick Mode PS> New-AzureQuickVM -Linux –ServiceName "myLinuxEnv" -Name "SUSE-02"
–ImageName "b4590d9e3ed742e4a1d46e5424aa335e__SUSE-Linux-Enterprise-
Server-11-SP2-New" -LinuxUser "root" -Password P@ssw0rd -AffinityGroup
"CoontosoAffinityGroup"
In this scenario, you will create a Windows Azure virtual machine that is running the Windows operating system using the advanced mode in order to add extra configurations that are not available using the quick mode, such as virtual machine disk and endpoint configurations. For this purpose, you will use a combination of the following Azure cmdlets:
You can use the following code:
#Create Azure VM configuration PS> $vm1 = New-AzureVMConfig -Name myWeb01 -InstanceSize Medium -ImageName
"a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-Datacenter-
201212.01-en.us-30GB.vhd" | Add-AzureProvisioningConfig -Windows –Password
"P@ssw0rd" –WindowsDomain –Domain "Contoso" –JoinDomain "Contoso.com"
–DomainUserName "Administrator" –DomainPassword "P@ssw0rd"
-MachineObjectOU "OU=Azure,DC=Contoso,DC=com" -DisableAutomaticUpdates
–ResetPasswordOnFirstLogon –TimeZone "Pacific Standard Time" #Create Azure VM using the previously created VM PS> New-AzureVM -ServiceName "ContosoWeb" -VMs $vm1
In this scenario, you have a secure website running on the Windows Azure virtual machine and you want to make this website accessible to other users. In order to achieve this task, you will have to create an endpoint that is configured to allow communication between users in different networks and the website on your virtual machine. Network Endpoint is similar to the concept of Network Address Translation (NAT) or the Port Forward features in network switches and routers.
To make your website accessible to other users, you will use the Add-AzureEndPoint cmdlet with the following parameters to add a new Not Load-Balanced (NoLB) endpoint to the secure website-utilizing port 443 for HTTPS:
You can use the following steps:
You can use the following code:
#Add NoLB EndPoint to Windows Azure virtual machine PS> Get-AzureVM -ServiceName "CorpWebsite" -Name "WebSrv01"
| Add-AzureEndpoint
-Name "HTTPs" -Protocol tcp -LocalPort 443 -PublicPort 443
| Update-AzureVM
In this scenario, you have cloud services running on the corporate website portal; these cloud services consist of three virtual web servers, and you want to make sure that load balancing is configured for this server. In order to achieve this task, you will have to add a new Load-Balancing Endpoint and assign this endpoint to all those virtual machines that should be members of the load balancing stack.
For this purpose, you will use the Add-AzureEndPoint cmdlet with the following parameters to add a new Load-Balanced (LB) EndPoint for the server hosting the website portal:
You can use the following steps:
You can use the following code:
#Add Load-Balanced EndPoint to Windows Azure virtual machine PS> Get-AzureVM -ServiceName CorpWebsite | Add-AzureEndpoint -Name
"LB-Http" -Protocol tcp -PublicPort 80 -LocalPort 80 -LBSetName
"LB-WebFarm" -ProbePort 80 -ProbeProtocol "http" -ProbePath "/"
| Update-AzureVM
In this scenario, you have a Windows Azure virtual machine with only one disk for the operating system, and you want to create a new data disk and attach it to this virtual machine. For this purpose, you will use the Add-AzureDataDisk cmdlet with the following group of parameters:
You can use the following steps:
You can use the following code:
#Create and Assign a new data disk to Windows Azure VM PS> Get-AzureVM -ServiceName "myWebFarm" -Name WebSrv01
| Add-AzureDataDisk
-CreateNew -DiskSizeInGB 30 –DiskLabel "UserDataDisk" -LUN 0
| Update-AzureVM
In this scenario, you want to migrate a virtual machine from your on-premise Hyper-V server to Windows Azure without rebuilding the server from scratch. So you have decided to move the local VHD file for the virtual machine to your storage on Windows Azure. For this purpose, you will use the Add-AzureVhd cmdlet with the following group of parameters:
You can use the following steps:
You can use the following code:
#Get the Azure Storage Account for the default Azure Subscription PS> $StorageAccountName = (Get-AzureSubscription).CurrentStorageAccount #Define DiskName PS> $DiskName = "AppVServerDisk" #Define Local VHD file path PS > $LocalVHD = 'D:Hyper-VVirtual Hard DisksAppVServer.vhd' #Define the URI for the Windows Azure Container PS > $Destination = 'http://' + $StorageAccountName + '.blob.core.windows.
net/vhds/AppVServerDisk.vhd' #Move VHD file from local server to Windows Azure Storage PS > Add-AzureVhd -LocalFilePath $LocalVHD -Destination $Destination #Convert the VHD file to Windows Azure Disk PS > Add-AzureDisk -OS Windows -DiskName $DiskName -MediaLocation
$Destination
In this scenario, you have a VHD for one of your virtual servers that has recently been moved from the on-premise Hyper-V server to the Windows Azure storage, and you want to create a new Windows Azure virtual machine using this VHD. For this purpose, you will use a combination of the following Azure cmdlets:
You can use the following code:
#Create Azure VM Configuration object PS> $vm1 = New-AzureVMConfig -Name AppVServer -InstanceSize Medium
-DiskName "AppVServerDisk" #Create new VM from Azure VM Configuration PS> New-AzureVM -ServiceName "ContosoWeb" -VMs $vm1
In this scenario, you have a customized Windows Azure virtual machine and you want to use this virtual machine as a base image for the future provisioning of virtual machines. For this purpose, you will use the Save-AzureVMImage cmdlet to capture the virtual machine and save it as an image.
The parameters of the Save-AzureVMImage cmdlet are as follows:
Make sure to Sysprep your virtual machine before using the Save-AzureVMImage cmdlet.
You can use the following code:
#Create Azure VM Image PS> Save-AzureVMImage -ServiceName "CorpWebsite" -Name "myWeb01"
-NewImageName "Corp Website Core Image, Update Jan 2013"
In this scenario, you have a Windows Azure virtual machine running under a specific cloud service and you want to move it to another cloud service. Unfortunately, there is no option in the Windows Azure portal that allows moving the virtual machine between different cloud services. The workaround is to use a combination of Windows Azure PowerShell cmdlets to achieve this goal. These cmdlets are as follows:
The Remove-AzureVM cmdlet removes the virtual machine but not the attached disk.
The Import-AzureVM cmdlet might import the virtual machine with a new IP Address.
You can use the following code:
#Export Azure VM configuration PS> Export-AzureVM -ServiceName CorpWebsite -Name myWeb01 -Path
$homedesktopmyWeb01.xml #Remove Azure VM PS> Remove-AzureVM -ServiceName CorpWebsite -Name myWeb01 #Importing Azure VM configuration file, and create new VM using the import
file PS> Import-AzureVM -Path $homedesktopmyWeb01.xml | New-AzureVM -
ServiceName CorpPortal
In this scenario, you have a large number of Windows Azure virtual machines and you spend a lot of time starting, restarting, or stopping these using the management portal. Using the management portal, you are doing this task one by one and you want to discover the other possibilities in PowerShell. For this purpose, Windows Azure PowerShell provides a quick and basic task equivalent to this:
All three cmdlets use the same parameters as follows:
You can use the following code:
#Start Azure VM PS> Start-AzureVM -ServiceName CorpWebsite -Name myWeb01 #Restart Azure VM PS> Restart-AzureVM -ServiceName CorpWebsite -Name myWeb01 #Shutdown Azure VM PS> Stop-AzureVM -ServiceName CorpWebsite -Name myWeb01
In this scenario, you have a Secure Socket Layer (SSL) certificate that you want to use for one of the services hosted on Windows Azure. In order to use it, you will have to upload it first to your Windows Azure subscription. For this purpose, you will use the Add-AzureCertificate cmdlet with the following group of parameters:
You can use the following code:
#Upload certificate to Windows Azure service PS> Add-AzureCertificate -ServiceName "myDevEnv" –CertToDeploy
<myCertificate.pfx> -Password abc123
In this scenario, you will generate a remote desktop file for your Windows Azure virtual machines so you can connect to them directly instead of using the Windows Azure portal. For this purpose, you will use the Get-AzureRemoteDesktopFile cmdlet with the following group of parameters:
You can use the following code:
#Generate Remote Desktop File for Windows Azure VM PS> Get-AzureRemoteDesktopFile -ServiceName "myDevEnv" –Name
"DevTools" -LocalPath $homeDesktopDevTools.rdp –Launch
It is very obvious that cloud computing is the future of our ICT industry; it is going to be a core component in each and every entity, and this is no secret. There are huge benefits and roadmaps provided by this technology for future growth.
In this article, we have seen Microsoft Windows Azure and SQL Azure as a real-life example of a cloud computing implementation, and we have learned how Windows PowerShell can play a major role in operating such a technology easily, as if managing a normal virtualized environment.
In the next article, we will talk about IT Process Automation (also known as Runbook automation) and the concept behind it. Also, we will learn how Windows PowerShell and System Center Orchestrator can be integrated together to implement and complete this concept in real life.
Further resources on this subject:
I remember deciding to pursue my first IT certification, the CompTIA A+. I had signed…
Key takeaways The transformer architecture has proved to be revolutionary in outperforming the classical RNN…
Once we learn how to deploy an Ubuntu server, how to manage users, and how…
Key-takeaways: Clean code isn’t just a nice thing to have or a luxury in software projects; it's a necessity. If we…
While developing a web application, or setting dynamic pages and meta tags we need to deal with…
Software architecture is one of the most discussed topics in the software industry today, and…