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>"