Thursday, 13 October 2016

Installing Azure PowerShell from the PowerShell Gallery.


If you want to manage Azure from powershell, then you need to install Azure powershell modules, without that you can’t manage any Azure resources using powershell.

So here is the question how to install azure powershell ?
Normally from windows 7 onwards powershell is inbuilt feature of windows. 
To install azure powershell on you  system there are two methods, one is using Webpi and another one is using powershell, please follow as mentioned below.

Method 1.

 Installing Azure PowerShell 1.0 and greater from WebPI is the same as it was for 0.9.x. Download Azure PowerSehll Download and start the install. If you have Azure PowerShell 0.9.x installed, version 0.9.x will be uninstalled as part of the upgrade. If you installed Azure PowerShell modules from PowerShell Gallery, the installer automatically removes the modules before installation to ensure a consistent Azure PowerShell environment.

Method 2.

Open Windows powershell ISE as Administrator mode, and type below commands.

# Install the Azure Resource Manager modules from the PowerShell Gallery
Install-Module AzureRM

# Install the Azure Service Management module from the PowerShell Gallery
Install-Module Azure



#Set Execution Policy as remote Signed so that we can import script.
Set-ExecutionPolicy remotesigned

#Import the module now.
Import-Module azurerm

Once Azure PowerShell Installed, you are good to go and manage Azure.



Create Azure Windows VM using Powershell.

 Create a plenty new VM in Azure ARM portal, just you need to do is copy blow code and paste it into you powershell ISE .. make sure Powershell is opened as Administrator mode.
And in Global variables you just need to change the values according to your needs.
# ------------------------------------------Create New VM -----------------------------------------------

# Sign-in with Azure account credentials

Login-AzureRmAccount

# Select your Azure Subscription.

$subscriptionId =
    (Get-AzureRmSubscription |
     Out-GridView `
        -Title "Select an Azure Subscription ..." `
        -PassThru).SubscriptionId

Select-AzureRmSubscription `
    -SubscriptionId $subscriptionId

## Global Variables.

$ResourceGroupName = "srcresourcegrp01"
$location = "Southeastasia"

## Storage
$storageName = "srcstorage01"
$storageType = "Standard_A1"

## Network
$nicname = "srcnic"
$subnetName = "srcsubnet"
$vnetName = "srcvnet"
$vnetAddressPrefix = "10.0.0.0/16"
$vnetSubnetAddressPrefix = "10.0.0.0/24"
$publicIPName = "srcpublicip"

## Computer
$vmName = "srcvm"
$computerName = "srccomp"
$vmSize = "Standard_A1"
$osDiskName = $vmName + "osDisk"
$blobPath = "vhds/srcosDisk.vhd"

###############################################################################################################

# Create New Resource Group
New-AzureRmResourceGroup -Name $ResourceGroupName -Location $location

#Create New Storage account
Get-AzureRmStorageAccountNameAvailability $storageName
$storageAcc = New-AzureRmStorageAccount -ResourceGroupName $ResourceGroupName -Name $storageName -SkuName "Standard_LRS" -Kind "Storage" -Location $location

#Create a virtual network
$singleSubnet = New-AzureRmVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix $vnetSubnetAddressPrefix
$vnet = New-AzureRmVirtualNetwork -Name $vnetName -ResourceGroupName $ResourceGroupName -Location $location -AddressPrefix $vnetAddressPrefix -Subnet $singleSubnet

#Create a public IP address and network interface
$pip = New-AzureRmPublicIpAddress -Name $publicIPName -ResourceGroupName $ResourceGroupName -Location $location -AllocationMethod Dynamic
$nic = New-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $ResourceGroupName -Location $location -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id

#Create a virtual machine

#The password must be at 12-123 characters long and have at least one lower case character, one upper case character, one number, and one special character.
$cred = Get-Credential -Message "Type the User name and password of the local administrator account."


$vm = New-AzureRmVMConfig -VMName $vmName -VMSize $vmSize

$vm = Set-AzureRmVMOperatingSystem -VM $vm -Windows -ComputerName $computerName -Credential $cred -ProvisionVMAgent -EnableAutoUpdate
$vm = Set-AzureRmVMSourceImage -VM $vm -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus 2012-R2-Datacenter -Version "latest"
$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id

# Specify Blob Path

$osDiskUri = $storageAcc.PrimaryEndpoints.Blob.ToString() + $blobPath
$vm = Set-AzureRmVMOSDisk -VM $vm -Name $osDiskName -VhdUri $osDiskUri -CreateOption fromImage

#Finally, create the virtual machine.

New-AzureRmVM -ResourceGroupName $ResourceGroupName -Location $location -VM $vm

# The End.


Once you get success output, means your VM has been created and ready to use it.




Get SSL Certificate Expiry Notification on Mail.

 There are multiple ways to get SSL Certification expiry details/alert. We all know if our SSL certificate get expire, how critical situatio...