Quantcast
Channel: Azure Virtual Machines forum
Viewing all articles
Browse latest Browse all 12545

[Forum FAQ] Using Windows Azure PowerShell to operate Microsoft Azure Virtual Machines

$
0
0

Since Windows Azure PowerShell is a powerful tool that we can use to control the deployment and management our workloads in Windows Azure, in this article, we will introduce some basic configurations for Azure Virtual Machines via Windows Azure PowerShell.


To use Windows Azure PowerShell, we need to download and install Azure PowerShell module by running the Microsoft Web Platform Installer. Then, we can run Windows Azure PowerShell and connect to our subscription.


Here are some common operation tasks:


1. Create a Virtual network


If we already have created a virtual network in Windows Azure, we can edit the .netcfg file to create a new virtual network. Firstly, we can use Get-azureVnetConfig to retrieve the configuration file to a local file. (Figure 1)


Figure 1. Retrieve the virtual network configuration file via Windows Azure PowerShell


After that, we can add the following commands in Mynetwork.netcfg file and save it.


</VirtualNetworkSite>

      <VirtualNetworkSite name="test01" Location="West US">

        <AddressSpace>

          <AddressPrefix>10.0.0.0/8</AddressPrefix>

        </AddressSpace>

        <Subnets>

          <Subnet name="Subnet-1">

            <AddressPrefix>10.0.0.0/24</AddressPrefix>

          </Subnet>

          <Subnet name="Subnet-2">

            <AddressPrefix>10.0.1.0/24</AddressPrefix>

         </Subnet>

        </Subnets>


Note: In general, when we create a Virtual network, we need to choose an Affinity Group instead of a region. However, when we configure the .netcfg file, we can define a region for the virtual network by writing <VirtualNetworkSite name="xxx" Location="xxx"> instead of <VirtualNetworkSite name="xxx" AffinityGroup="xxx ">.


Then, we can use Set-AzureVNetConfig commands to reconfigure our virtual networks. (Figure 2)


Figure 2. Reconfigure virtual network configuration file via Windows Azure PowerShell


2. Create a new Cloud Service


We can use new-azureservice to create Cloud Service. (Figure 3)


Figure 3. Create a new Cloud Service via Windows Azure PowerShell


3. Create a Windows Azure Virtual Machine in the existing Virtual Network and Cloud Service


To create an Azure Virtual Machine, we can use an image from the gallery or our own image/disk. In this example, we use a windows server 2008 r2 image from the gallery. Firstly, we run “Get-AzureVMimage|Select ImageName” cmdlet to obtain the image name of the image that we want to use.


Then we run the commands in the figure 4:


Figure 4. Create a new virtual network via Windows Azure PowerShell


After that, we can obtain the detailed information of the Virtual Machine by using the Get-AzureVM cmdlets. (Figure 5)


Figure 5. Get the information of a Virtual Machine via Windows Azure PowerShell


4. Add an endpoint for Virtual Machine


To create an endpoint for an Azure Virtual Machine, we can use Get-AzureVM and Add-AzureEndpoint cmdlets, and Update-AzureVM to update the configuration for the Virtual Machine. (Figure 6)


Figure 6. Create an endpoint via Windows Azure PowerShell


5. Start/stop an Azure
Virtual Machine


We can use Start-AzureVM and
Stop-AzureVMcmdlets to start or shut down an AzureVirtual Machine. (Figure 7)



Figure 7. Start an Azure Virtual Machine via Windows Azure PowerShell


When we shut down an Azure
Virtual Machine via Windows Azure PowerShell, we need to notice that if we usethe Stop-AzureVM cmdlet without the -StayProvisioned parameter, then the Virtual Machine will be shut down to the status of Stopped (Deallocated) and you won’t be charged for the Virtual Machine.


However, Windows Azure resources and the IP address associated with thatVirtual Machine will be released. We can see the differences below:


When we
the Stop-AzureVM cmdlet with the -StayProvisioned parameter to shut down the Virtual Machine (Figure 8), we can see theVirtual Machine is in the stopped status from windows Azure management portal. (Figure 9)



Figure 8. Shut down an Azure Virtual Machine to the stopped status via Windows Azure PowerShell



Figure 9. Virtual Machine’s status in Windows Management portal


In addition, we can see the
Virtual Machine is in the stopped (Deallocated) status (Figure 10) after running Stop-AzureVM without –StayProvisioned parameter. If it is the unique Virtual Machine in the cloud service, it will prompt that the public IP address for your cloud service would be changed. (Figure 11)



Figure 10. Virtual Machine’s status in Windows Management portal



Figure 11. Shut down an Azure Virtual Machine to the stopped (deallocated) status via Windows Azure PowerShell


6. Create an Availability Set


To create an availability set, we can specify it by add –AvailabilitySetName parameter inNew-AzureVMConfig cmdlets. Since we have created the
Virtual Machine, we use the Cmdlets in Figure 12  to add theVirtual Machine to a new Availability Set and this will cause theVirtual Machine reboot.



Figure 12. Create an Availability Set via Windows Azure PowerShell


Then we can check in the virtual machine management portal, the Virtual Machine is added to the
Availability Set test123. (Figure 13)


Figure 13. Configure panel of the Azure Virtual Machine Management Portal


7. Delete an Azure Virtual Machine


In general, we use the Remove-AzureVM cmdlet to delete a Windows Azure Virtual Machine and itdoes not remove the VHD for the Virtual Machine. In addition, we can add –deletevhd parameter to delete the VHD.(Figure 14)



Figure 14. Delete an Azure Virtual Machine via Windows Azure PowerShell


More information:


Create or Delete Virtual Machines Using Windows Azure Cmdlets

http://msdn.microsoft.com/en-us/library/jj835085.aspx


Azure Service Management Cmdlets

http://msdn.microsoft.com/en-us/library/dn495240.aspx


Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.


Viewing all articles
Browse latest Browse all 12545

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>