Learn about Windows PowerShell
Summary: Microsoft senior technical evangelist talks about getting started with virtual machine’s in the cloud by using Windows Azure and Windows PowerShell.
Microsoft Scripting Guy, Ed Wilson, is here. Today we have as a guest blogger, Keith Mayer.
Keith Mayer is a senior technical evangelist at Microsoft. He focuses on the Windows infrastructure, data center virtualization, systems management, and private cloud. Keith has over 20 years of experience as a technical leader of complex IT projects, in diverse roles such as network engineer, IT manager, technical instructor, and consultant. He has consulted and trained thousands of IT professionals worldwide about the design and implementation of enterprise technology solutions.
You can find Keith online at http://KeithMayer.com.
And now, here’s Keith…
Windows Azure Infrastructure Services provides the ability to easily provision or migrate storage, virtual machines, and virtual networks onto the global Windows Azure cloud platform by using a cost-effective Pay-As-You-Go model. Since the launch of Windows Azure infrastructure services in April 2013, there’s been a ton of interest from IT pros regarding a number of key scenarios involving Windows Azure virtual machines, such as:
And these scenarios are just the start.
To begin leveraging the elastic capabilities of Windows Azure to its fullest, we need to be able to handle provisioning and management in an automated way—and, that’s where Windows PowerShell comes in!
In this post, we’ll step through the tasks involved in leveraging the Windows Azure PowerShell module to:
To learn more about the basics of the Windows Azure infrastructure services, you may also be interested in the “Early Experts” Cloud Quest and our scenario-based Cloud Labs Step-by-Step Guides. Both are FREE online study resources that provide hands-on lab exercises for leveraging Windows Azure and building key IT pro cloud scenarios.
To automate the provisioning and management of Window Azure, you’ll need the Windows Azure PowerShell module. The Windows Azure team makes this module available as a free download, and this module provides approximately 180 Windows PowerShell cmdlets for automating Windows Azure storage, virtual machines, virtual networks, and other cloud services.
To get started, you’ll need the following prerequisite items:
After you satisfy these prerequisites, you’ll be prepared to follow along with the rest of this post.
After downloading and installing the Windows Azure PowerShell module, you need to perform the following initial steps from Windows PowerShell to configure connection information for your Windows Azure subscription. After you perform these steps the first time, the configuration is saved locally, and you do not need to perform these steps again.
1. Set the Windows PowerShell script execution policy to RemoteSigned:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
2. Import the Windows Azure PowerShell module:
3. Download the Windows Azure Publish Settings file for your Windows Azure subscription. When you run this cmdlet, a web browser launches and asks you to sign in. Sign in with the same user name and password credentials that you used when you activated your Windows Azure subscription.
Note When you save your Publish Settings file, specify a short easily-typed file name to save your file. You need to type the complete path to this file name in the next step.
4. Import the downloaded Windows Azure Publish Settings file into your Windows PowerShell environment. This updates your Windows PowerShell environment with the connection and certificate information that is needed to connect and authenticate to your Windows Azure subscription.
Import-AzurePublishSettingsFile -PublishSettingsFile "full path to downloaded file"
Note After you import the downloaded Publish Settings file, store it in a secure location. The Publish Settings file contains certificate information that can be used to authenticate to your Windows Azure subscription, and as such, it should be treated with the same security precautions that you normally observe for storing administrative credentials.
After you complete the steps in this section, Windows PowerShell is configured to connect to your Windows Azure subscription. To test this connection, enter the following cmdlet to connect to Windows Azure and enumerate your subscription information:
Success! The Windows Azure subscription results from the Get-AzureSubscription cmdlet.
Prior to provisioning virtual machines on Windows Azure, we need to set up a Windows Azure storage account so that we have a location where virtual machines can store their associated virtual hard disks (VHDs). Each storage account in Windows Azure can be used as a storage volume that grows dynamically as more data is copied into it—up to 100 TB in size per storage account!
Provision a new storage account on Windows Azure by using the following steps:
1. Get a list of valid Windows Azure data center locations for provisioning storage and compute services. You need to specify a data center location as part of provisioning new resources.
Note All data center locations do not provide the same AvailableServices, as shown in the previous command output. You need to select a data center location that provides both the Storage and PersistentVMRole services to provision storage and virtual machines. For this post, I will use the East US data center location, because that’s the location closest to where I’m stationed.
2. Create a Windows Azure affinity group that specifies the data center location you selected. Affinity groups in Windows Azure are used to collect storage, virtual machines, and virtual networks that are used for a common set of applications. They help place these components within a reduced number of network hops in the selected Windows Azure data center location to improve performance between related services. In the following command, I provision a new Windows Azure affinity group named pslab-group in the East US data center location:
New-AzureAffinityGroup -Name pslab-group -Location "East US"
3. Next, let’s provision a new Windows Azure storage account that uses the affinity group defined previously to determine the data center location. In this example, I set up a new storage account named pslabstorage:
New-AzureStorageAccount -StorageAccountName pslabstorage -AffinityGroup pslab-group
Note Windows Azure storage account names are required to be globally unique. If you receive an error message that states the name already exists, try using a different name.
4. Our new Windows Azure storage account is provisioned, but we want to set this new storage account as our default storage location for our subscription by using the following command:
Get-AzureSubscription | Set-AzureSubscription -CurrentStorageAccount pslabstorage
Now, our new Windows Azure storage account is provisioned and we’re ready to provision a new virtual machine in the cloud!
To start building a new virtual machine in the cloud, we need to select an appropriate virtual machine image, and then use that image to build a new virtual machine.
1. Generate a list of available Windows Azure platform images for new virtual machines:
There are several platform images that will be returned for virtual machines, which are available for Windows Server 2012, Windows Server 2008 R2 with SP1, SQL Server 2012, BizTalk, SharePoint Server 2013, and several Linux distributions. When you select the platform image for building a new virtual machine, you need to supply the ImageName value. Unfortunately, as shown earlier, the ImageName value can be a very long value to enter! It’s much easier to use the Label value to select the appropriate image, and then return the related ImageName value into a variable as follows:
$VMImage = @(Get-AzureVMImage | Where-Object -Property Label -Match "Windows Server 2012 Datacenter, May 2013").ImageName
Perfect! Now $VMImage is storing the ImageName for our selected platform image, which we can use when provisioning a new virtual machine on the Windows Azure cloud platform.
2. Prior to provisioning our new virtual machine, let’s set a few Windows PowerShell variables for some of the common parameters that you may want to customize, such as the virtual machine name, Admin user name, and Admin password:
$myVMName = "pslabvm01" $myAdminName ="pslabAdmin" $myAdminPwd ="psl@bp@ssw0rd"
3. Now, we’re ready to build our new virtual machine in Windows Azure. To configure on our new virtual machine during the provisioning process, we use the New-AzureQuickVM cmdlet to specify the virtual machine image, virtual machine name, and local Admin credentials. In addition, we’ll specify the Windows Azure affinity group that we configured earlier so our storage and virtual machines will be organized in a common affinity group to improve performance.
New-AzureQuickVM -ImageName $VMImage -Windows -Name $myVMName -ServiceName $myVMName -AdminUsername $myAdminName -Password $myAdminPwd -AffinityGroup pslab-group
After a few minutes…Presto! Our new virtual machine is created in the Windows Azure cloud (as depicted in the previous screenshot) with an OperationStatus of Succeeded.
Note The value used for the ServiceName parameter is required to be globally unique. If you receive an error message that states this name already exists, try using a different ServiceName value.
4. Our new virtual machine is now provisioned, and we can check on its status by using the Get-AzureVM cmdlet:
Get-AzureVM -Name $myVMName -ServiceName $myVMName
Note Provisioning a new virtual machine takes a few minutes, so be sure to check the InstanceStatus property to determine when provisioning is complete. When the virtual machine is fully provisioned and online, this property returns a value of ReadyRole as indicated in the previous output.
5. At this point, you can use the following cmdlets to interact with the new virtual machine to stop, start, and restart the virtual machine operating system state:
Stop-AzureVM -Name $myVMName -ServiceName $myVMName Start-AzureVM -Name $myVMName -ServiceName $myVMName Restart-AzureVM -Name $myVMName -ServiceName $myVMName
Now you can manage this virtual machine by signing in to the Windows Azure account site using the same credentials that you used when you activated your Windows Azure subscription.
You’ve completed the provisioning process for a new virtual machine in Windows Azure infrastructure services by using Windows PowerShell! Now that you’ve walked through the basic steps involved in using the Windows Azure PowerShell module with Windows Azure infrastructure services, leverage these additional resources to continue your learning:
Keith, this is an excellent post. Thank you for sharing it with us.
Join me tomorrow when I have a guest blog post by Alan Byrne about the Office 365 Web Service—it is not to be missed!
I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at firstname.lastname@example.org, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.
Ed Wilson, Microsoft Scripting Guy
Great Post to get started with Azure + PowerShell :)
I have PowerShell 2.0 running on my system.
Which version of Azure PowerShell SDK supports that ?
I am unable to set the new storage account created as the default location for my subscription... get the error -
Set-AzureSubscription : The input object cannot be bound because it did not contain the information required to bind all mandatory parameters: Certificate
Could you please guide me in resolving this...
Thanks and warm regards,
Totally agree with Dexter and kennydust... excellent post... Thank you so much! I worked around that error, and was able to provisioning new VMs...
http://msdn.microsoft.com/en-us/library/windowsazure/jj835083.aspx -- Looks exactly like what I need. Pity it doesn't exist.
Is there something like it?
Try this link:
Set-AzureSubscription : The input object cannot be bound because it did not contain the information required to bind
all mandatory parameters: Certificate
At line:1 char:25
+ Get-AzureSubscription | Set-AzureSubscription -CurrentStorageAccount jsteststora ...
+ CategoryInfo : InvalidArgument: (Microsoft.Windo...ureSubscription:PSObject) [Set-AzureSubscription], P
+ FullyQualifiedErrorId : InputObjectMissingMandatory,Microsoft.WindowsAzure.Commands.Profile.SetAzureSubscription
Great Post. Very helpful. Thanks