PowerShell scripts enable automated cloud deployments

Programmatically repeatable processes are a major concept in cloud computing. Infrastructure deployment via the graphical interface takes time, and human error can creep in. IT administrators should learn to build automated cloud deployments.

By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.

You also agree that your personal information may be transferred and processed in the United States, and that you have read and agree to the Terms of Use and the Privacy Policy.

There’s a breadth of infrastructure provisioning tools available with automation capabilities. Administrators can adopt PowerShell to automate cloud and on-premises deployments across Microsoft products. The following steps guide a PowerShell user through Microsoft Azure deployment via the Azure PowerShell cmdlets.

The steps in this tutorial create and launch a virtual server on Azure. An infrastructure as a service (IaaS) cloud deployment occurs in two sets of processes: the initial setup of networks, firewalls, resource groups and storage and then the creation and deployment of VMs for workloads.

Before you deploy a VM into Azure’s IaaS environment, know the requirements for the service or infrastructure that will run there. If you perform the process correctly first, you will save time later. With the initial setup values in place, cloud admins skip the tedious process to add each item into the command directly.

This deployment relies on a resource group that puts together logically related work items. Using resource groups makes it easier to manage the included items. Your cloud deployment will be tidy, and you can take action on the resource group rather than each component.

Build the infrastructure

To start the automated cloud deployment, open PowerShell, and log into Azure using the command:

Login-AzureRMAccount

Enter your Azure credentials when prompted — the output will show your subscription ID and other items. Create the required resource group that will contain all the VM items:

Substitute the name entry TechTargetTestGroup for one of your own creation. Give the resource group a useful and recognizable name, such as what application it will host. Lastly, use whichever Azure location you desire; this tutorial uses the East US region.

Configure the underlying network items for network connectivity in the resource group. This includes networks, subnets, public IP addresses and network security groups.

The code below assigns all important items to variables, which are denoted by the $ character. Eventually, commands utilize the variables, in place of the text of the variable. Cloud automation in this way makes work much easier.

The networks and public IP address are now configured. Network security groups (NSGs) are the equivalent in an Azure deployment of firewall rules, applied to one or many items or resource groups to manage access.

It will take several minutes to build the VM and even longer for the remote desktop connection to become available. To check the progress, log into the Azure portal, navigate to the resource group and click on the VM. If it is still building, it will report Creating. Eventually, if all went according to plan, PowerShell will report success.

Figure 3. PowerShell reports proof of deployment success.

To connect to the VM created earlier, click the Connect icon from the Azure VM ribbon. This will prompt the download of an RDP configuration file that can be read and imported by the RDP client.

Figure 4. This listing shows the components of the script that automated a cloud deployment.

Finally, those powered-up servers will consume resources in your cloud deployment. To delete the entire environment, navigate to the resource group, select Delete and input the resource group name. It will remove all the setup that you created. This action illustrates why an administrator’s life will be easier if they group the components together into logical items.

These fundamentals enable an administrator to automate deployment of VMs on Azure IaaS. All of the Azure services are available via PowerShell, and an admin can set up and consume them in the same fashion.