Saturday, October 10, 2015

Moving a VM to a new Subnet using Powershell Commands

You can move a VM to a new subnet with the management portal or Windows PowerShell Commands

Get-AzureVM -ServiceName "<CloudServiceName>"
            -Name "<VMName>"
Set-AzureSubnet -SubnetName "<SubnetName>"
Update-AzureVM

Wednesday, October 7, 2015

Creating an Online or Offline Secondary Database using PowerShell Commands

a. To create an online Secondary Database

Start-AzureDqlDatabaseCopy -ServerName "<Secondary Server Name>"
                           -DatabaseName "<Database Name>"
                           -PartnerServer "NewServer"
                           -ContinuousCopy

b. To create an Offline Secondary Database

Start-AzureDqlDatabaseCopy -ServerName "<Secondary Server Name>"
                           -DatabaseName "<Database Name>"
                           -PartnerServer "NewServer"
                           -ContinuousCopy
                           -OfflineSecondary   

Access Storage Logs with PowerShell Commands

When Storage Logging is configured, log data is saved to blobs in the $logs container created for the storage account.

You can access logs with the Get-AzureStorageBlob command and filter logs by filename and metadata.

Get-AzureStorageBlob -Container '$logs' |
where {
    $_.Name -match 'blob/YYYY/MM/DD/HHMM' -and
    $_.ICloudBlob.Metadata.LogType -match 'write'
}
foreach {
 "{0}{1}{2}{3}" -f $_.Name,
 $_ICloudBlob.Metadata.StartTime,
 $_ICloudBlob.Metadata.EndTime,
 $_ICloudBlob.Metadata.LogType
}
           

Configuring Storage Logging and Retention using PowerShell Commands

A. To enable Storage Logging for Read, Write and Delete Actions with Retention period of 30 days,

Set-AzureStorageServiceLoggingProperty 
                    - ServiceType Blob
                    -LoggingOpertaions read,write,delete
                    -RetentionDays 30 

Set-AzureStorageServiceLoggingProperty 
                    - ServiceType Table
                    -LoggingOpertaions read,write,delete
                    -RetentionDays 30 

Set-AzureStorageServiceLoggingProperty 
                    - ServiceType Queue
                    -LoggingOpertaions read,write,delete
                    -RetentionDays 30 

B. To disable collection of metrics

Set-AzureStorageServiceLoggingProperty 
                    - ServiceType Blob
                    -LoggingOpertaions none

Set-AzureStorageServiceLoggingProperty 
                    - ServiceType Table
                    -LoggingOpertaions none

Set-AzureStorageServiceLoggingProperty 
                    - ServiceType Queue
                    -LoggingOpertaions none

Configuring Storage Metrics and Retention using PowerShell Commands


  • Azure Storage has in-built analytics feature called Azure Storage Analytics used for collecting metrics and logging storage request activity. 
  • You enable Storage Analytics Metrics to collect aggregate transactions and capacity data and you enable Storage Analytics Logging to capture Successful and Failed request attempts to your Storage Account.


There are 2 levels of metrics collections:
  1. Service Level: These metrics include aggregate statistics for all requests, aggregated at a specific interval.
  2. API Level: These metrics record every request to each service only if a request is made within the hour interval


a. To enable Service level metrics collected by minute for blobs, tables and queues with unlimited retention

Set-AzureStorageServiceMetricsProperty -MetricsType Minutes
                                       -ServiceType Blob
                                       -MetricsLevel Service
                                       -RetentionDays 0

Set-AzureStorageServiceMetricsProperty -MetricsType Minutes
                                       -ServiceType Table
                                       -MetricsLevel Service
                                       -RetentionDays 0

Set-AzureStorageServiceMetricsProperty -MetricsType Minutes
                                       -ServiceType Queue
                                       -MetricsLevel Service
                                       -RetentionDays 0

b.To enable Service and API level metrics collected by Hour for blobs, tables and queues with 90 days of retention period

Set-AzureStorageServiceMetricsProperty -MetricsType Hour
                                       -ServiceType Blob
                                       -MetricsLevel ServiceAndApi
                                       -RetentionDays 90

Set-AzureStorageServiceMetricsProperty -MetricsType Hour
                                       -ServiceType Table
                                       -MetricsLevel ServiceAndApi
                                       -RetentionDays 90

Set-AzureStorageServiceMetricsProperty -MetricsType Hour
                                       -ServiceType Queue
                                       -MetricsLevel ServiceAndApi
                                       -RetentionDays 90
C. To Disable the collection of metrics

Set-AzureStorageServiceMetricsProperty -ServiceType Blob
                                       -MetricsLevel None


Set-AzureStorageServiceMetricsProperty -ServiceType Table
                                       -MetricsLevel None


Set-AzureStorageServiceMetricsProperty -ServiceType Queue
                                       -MetricsLevel None




Tuesday, October 6, 2015

Different URLs used in Azure

  • Existing Portal: https://manage.windowsazure.com
  • Preview Portal: https://portal.azure.com
  • Hosted Websites:  http://websitename.azurewebsites.net
  • Blobs: http://<storage account name>.blob.core.windows.net/<container name>/<blob name>
  • Blob Content: http://<storage account name>.blob.core.windows.net/<container name>/<your path and file name>
  • Access blobs via CDN : http://<your CDN subdomain>.vo.msecnd.net/<container name> /<blob path>
  • Access blobs via HTTPs and custom domain: https://<domain name>/<container name>/<blob path>
  • Table : http://<storage account name>.table.core.windows.net/<table name>
  • TO query entities in a specific table : https://<storage account name>.table.core.windows.net/<table name>(Partition Key='<partition key>',RowKey='<row key>')?$select=<comma separated property names>
  • Queues: http://<Storage account name>.queue.core.windows.net/<queue>
  • Storage Logs: https://<storage account name>.blob.core.windows.net/$logs
  • Accessing VM: https://<VM Name>.cloudapp.net
  • File Share: https://<Storage account name>.file.core.windows.net/<ShareName>
  • Azure Database: <database server name>.database.windows.net

 


Monday, October 5, 2015

Powershell commands for Mounting a File Share

To access the share within a VM, you mount it to your VM. You can mount a share to a VM so that the file share is available indefinitely to the VM, regardless of restarts.

a- To make the Storage Account credentials available across VM restarts, add them to the Windows Credential Manager:

cmdkey /add:<Storage-AccountName>.file.core.windows.net /user:<StorageAccountName> /pass:<StorageAccountKey>

b- Mount the file share using the Stored Credentials: Generally drive Z is used

net use z: \\ <Storage-AccountName>.file.core.windows.net\<ShareName>

c-To ensure a persistent file share that will survive any VM restart:

net use z: \\ <Storage-AccountName>.file.core.windows.net\<ShareName> /Persistent: YES

d- To verify that the network share was added or continues to exist:

net use

Drive Z will shows 5TB drive mounted in Windows Explorer.

PowerShell command to create a File Share

The following commands first creates an Azure Storage context, which encapsulates the Storage Account name and Key and then uses that context to create a file share:

$ctx= New-AzureStorageContext <Storage-AccountName>  <Storage-AccountKey>

New-AzureStorageShare <ShareName> -Context $ctx

With a file share in place, you can access it from any VM as long as they are in the SAME REGION as the share.



Configuring an Availibity Set using PowerSell commands

Currently an availability set can be created using Windows PowerShell only during the process of creating a new VM:

New-AzureVMConfig -Name <VMName>
                  -InstanceSize <InstanceSize>
                  -ImageName <ImageName>
                  -AvailibilitySetName <AvailibilitySetName> |
Add-AzureProvisioningConfig  -Windows
                             -Password <Password>
                             -AdminUserName <UserName> |
New-AzureVM -ServiceName <CloudServiceName>

To provision and Start the VM:

Start-AzureVm -ServiceName <CloudServiceName>
              -Name <VmName>

After creating it, the Availability Set can be changed:

  Get-AzureVM -ServiceName "<CloudServiceName>"
              -Name "<VMName>" |
  Set-AzureAvailibilitySet -AvailibilitySetName "<AvailibilitySetName>" |
Update-AzureVM
                            
                              

PowerShell for Scaling up and Scaling down VM Size

Get-AzureVM -ServiceName "<CloudServiceName>"
            -Name "<VMName>" |
Set-AzureVMSize  -InstanceSize "<InstanceSize>" |
Update-AzureVM

PowerShell for Configuring Idle Timeout for a load Balanced Endpoint Set

The idle timeout for a load balanced endpoint set can be configured only after the creation

Set-AzureLoadBalancedEndpoint -ServiceName "<CloudServiceName>"
                              -LBSetName "<SetName>"
                              -Protocol tcp
                              -LocalPort <PrivatePort>
                              -ProbeProtocolTCP
                              -ProbePort <ProbePort>
                              -IdleTimeoutInMinutes <NumMinutes>

PowerShell to configure idle timeout for an endpoint

The idle timeout for a public Azure endpoint can only be configured at the time of creating the endpoint:

Get-AzureVM -ServiceName "<CloudServiceName>
                        -Name "<VMName>" |
Add-AzureEndpoint -Name "<EndpointName>"
                                  -Protocol "tcp"
                                  -PublicPort <PublicPort>
                                  -LocalPort <PrivatePort>
                                  -IdleTimeInMinutes <NumMinutes> |
Update-AzureVM

PowerShell Commands to prepare the DSC Configuration Package

After creating the configuration script and allocating any resources it requires, produce a compressed zip file containing the configuration and the resources :

Publish-AzureVMDSCConfigurtion DeployWebPage.ps1 - ConfigurationArchivePath DeployWebPage.ps1.zip

When you build your configuration zip using Publish-AzureVMDSCConfiguration, it will not automatically include all the resources you specify, for example additional Windows PowerShell module dependencies or any files or folders that you intend to deploy. You must add those manually to the zip file before configuring the VM with the script.

Power shell DSC Configuration Keyword

PowerShell Desired State Configuration (DSC) uses Configuration Keyword to express the desired state of one or more target nodes.

Below configuration indicates that the server should have IIS enabled during provisioning :

Configuration EnableIIS
{
  Node WebServer
  {
     WindowsFeature IIS {
                     Ensure = "Present"
                     Name= "Web-Server"
                         }
  }
}

How to install and configure

Powershell commands for Copying Image Between Storage Accounts:

Use AZCopy Utility:

 AzCopy /Source: https://<SourceStorageAccountName>.blob.core.windows.net/
<SourceContainerName>
      /Destination:
https://<DestinationStorageAccountName>.blob.core.windows.net/<DestinationContainerName>
      /SourceKey:<SourceStorageKey>
      /DestinationKey:<DestinationStorageKey> 
      /Pattern:<ImageFileName>

Powershell command for Creating a VM instance from VM Image:

For Windows



New-AzureQuickVM -Windows

                 -Location "<LocationName>"


                 -ServiceName "<CloudServiceName>"


                 -Name "<VMName>"


                 -InstanceSize "<InstanceSize>"


                 -ImageName "<ImageName>"


                 -AdminUserName "<UserName>"


                 -Password "<Password>"


                 -WaitForBoot
 



FOR Linux



New-AzureQuickVM -Linux

                 -Location "<LocationName>"


                 -ServiceName "<CloudServiceName>"


                 -Name "<VMName>"


                 -InstanceSize "<InstanceSize>"


                 -ImageName "<ImageName>"


                 -LinuxUser"<UserName>"


                 -Password "<Password>"


                 -WaitForBoot

Powershell command to Capture a VM as a VM Image:

You can capture a stopped VM as VM Image using Save-AzureImage

 Save-AzureVMImage -ServiceName "<CloudServiceName>"
                  -Name "<VmName>"
                  -OSState "<GeneralizedOrSpecialized>"
                  -NewImageName "<ImageName>"
                  -NewImageLabel "<ImageLabel>"


•for a Generalized VM- OSState= Generalized
•for a Specialized VM- OSState= Specalized

Powershell commnd to Attach data disks to a VM:

Use import parameter set of Add-AzureDataDisk

   Get-AzureVM "<CloudServiceName>" -Name "<VMName>"
| Add-AzureDataDisk -Import
                    -DiskName "<DiskName>" 
                    -LUN <LUN#>
| Update-AzureVM 

 LUN: logical unit number location for data disk in VM(0-15)

Power shell command for Creating an Operating System disk or Data Disk from a VHD:

To create a bootable Windows OS disk from VHD:
Add-AzureDisk -DiskName "<DiskName>"
              -MediaLocation "http://<StorageAccountName>.blob.core.azure.com/<ContainerName>/
<FileName>.vhd"
              -Label "<Label>"
              -OS "Windows"
To create a bootable Linux OS from VHD:
Add-AzureDisk -DiskName "<DiskName>"
              -MediaLocation "http://<StorageAccountName>.blob.core.azure.com/<ContainerName>/
<FileName>.vhd"
              -Label "<Label>"
              -OS "Linux"

To create a data disk from VHD:

 Add-AzureDisk -DiskName "<DiskName>"
              -MediaLocation "http://<StorageAccountName>.blob.core.azure.com/<ContainerName>/
<FileName>.vhd"
              -Label "<Label>"