Tuesday, 20 June 2017

Creating a Image from existing Server in Azure ARM

Azure Image and configuring server with this image

1. Copy the OS disk of the server which you want to take image into a new container of a storage account and in the same container copy other disks of the server which you are taking image through Microsoft Storage Explorer.

2. Copy the URL of the OS disk and data disks into a notepad.

3. Run the following Script in PowerShell, before running the script change the parameter to the required values
Azure PowerShell Script

Login-AzureRmAccount

$subscription = (Get-AzureRmSubscription).SubscriptionName | Out-GridView -Title "Select Azure Subscription" -PassThru

Select-AzureRmSubscription -SubscriptionId "******************************"

$name = "VMName"
$nam = "PIPname"
$vmSize="Standard_F8"
$adminUsername=""
$adminPassword="********"
$sourceImageUri = 'https://sprabstor1.blob.core.windows.net/vhds/sprab007.vhd'
$diskName= $name + "OS-Disk"


$rgName="RGName"
$locName=""
$saName="StorageAccount"
$vnetName="VnetName"
$subnetIndex= '0'
$cred = New-Object PSCredential $adminUsername, ($adminPassword | ConvertTo-SecureString -AsPlainText -Force)


# Get the existing virtual network
$vnet=Get-AzureRMvirtualNetwork -Name $vnetName -ResourceGroupName $rgName

# Create the NIC
$nicName="NICname"
$pipName= $nam + "_pip"
$domName= $name
$pip=New-AzureRmPublicIpAddress -Name $pipName -ResourceGroupName $rgName -DomainNameLabel $domName -Location $locName -AllocationMethod Dynamic
$nic=New-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $rgName -Location $locName -SubnetId $vnet.Subnets[$subnetIndex].Id -PublicIpAddressId $pip.Id

# Specify the name, size
$vmName= $name
$vm=New-AzureRmVMConfig -VMName $vmName -VMSize $vmSize

# Specify the local administrator account, and then add the NIC
# Note : here you have to choose between creating a Linux or a Windows machine (see command bellow)
$vm=Add-AzureRMVMNetworkInterface -VM $vm -Id $nic.Id
$vm=Set-AzureRmVMOperatingSystem -VM $vm -Windows -ComputerName $vmName -Credential $cred


# Specify the OS disk name
$storageAcc=Get-AzureRMStorageAccount -ResourceGroupName sprabrg -Name $saName
$osDiskUri=$storageAcc.PrimaryEndpoints.Blob.ToString() + "vhds/" + $diskName  + ".vhd"

# Create the VM from the captured image
# Note : here you have to choose between creating a Linux or a Windows machine (see command bellow)
$vm=Set-AzureRMVMOSDisk -VM $vm -Name $diskName -VhdUri $osDiskUri -CreateOption fromImage -SourceImageUri $sourceImageUri -Windows
New-AzureRmVM -ResourceGroupName $rgName -Location $locName -VM $vm



It will take some time for the server to get deployed after deploying attach the copied data disk of the imaged server to the new server.

Monday, 13 March 2017

Migrate MSAzure VM Image from Classic to ARM portal

Migrate the Classic Image to ARM

First get the VM disks storage path.

OS disk : https://xxxx.blob.core.windows.net/vhds/PublicServer-os-2017-03-06-BC0F1E4.vhd
Disk 1 :-
https://xxxx.blob.core.windows.net/vhds/PublicServer-datadisk-0-2017-03-06-BC0F1E4.vhd

Disk 2 :
https://xxxx.blob.core.windows.net/vhds/PublicServer-datadisk-1-2017-03-06-BC0F1E4.vhd

In another ARM, Create a Storage & Container

New ARM Stroage account Name : magnatemplate


Container Name : https://template.blob.core.windows.net/temcon

Download & Install the Microsoft Azure Storage Explorer tool and add both the accounts in that tool and found the source disks & copy in to the destination disk


Create a VM from a specialized VHD disk using this https://azure.microsoft.com/en-us/resources/templates/201-vm-specialized-vhd/

and Click Deploy to Azure in ARM portal

Once VM has deployed, We need to create the image from that VM

using below link to make the sysprep and create a VM

https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-windows-generalize-vhd?toc=%2fazure%2fvirtual-machines%2fwindows%2ftoc.json

Prerequisites to take the Image :

Log in to Azure PowerShell
Open Azure PowerShell and sign in to your Azure account.

Copy
PowerShell
 Login-AzureRmAccount
A pop-up window opens for you to enter your Azure account credentials.

Get the subscription IDs for your available subscriptions.

Copy
PowerShell
 Get-AzureRmSubscription
Set the correct subscription using the subscription ID.

Copy
PowerShell
 Select-AzureRmSubscription -SubscriptionId "<subscriptionID>"
Deallocate the VM and set the state to generalized
Deallocate the VM resources.

Copy
PowerShell
 Stop-AzureRmVM -ResourceGroupName <resourceGroup> -Name <vmName>
The Status for the VM in the Azure portal changes from Stopped to Stopped (deallocated).

Set the status of the virtual machine to Generalized.

Copy
PowerShell
 Set-AzureRmVm -ResourceGroupName <resourceGroup> -Name <vmName> -Generalized
Check the status of the VM. The OSState/generalized section for the VM should have the DisplayStatus set to VM generalized.

Copy
PowerShell
 $vm = Get-AzureRmVM -ResourceGroupName <resourceGroup> -Name <vmName> -Status
 $vm.Statuses

Command to create the image

 Save-AzureRmVMImage -ResourceGroupName -Singapore-ARM  -Name magnapritemplate -DestinationContainerName magnatemcon -VHDNamePrefix cis1 -Path C:\Users\xxx\Desktop\New folder\Filename.json

You can get the output :

OperationId :
Status : Succeeded

Once created the image, go back to ARM portal again and more services -> templates-> add template-> General information->mention some name there, then ARM template-> (Open Filename.json file which is copied in local drive and copy & paste) in to the arm template

click add..

Deploy a VM :

More Services -> templates -> click the template which we created and there click deploy options and start to deploy
..............

Tuesday, 20 September 2016

Installing .Net Framework 3.5 With out OS Image for Windows 2012 Server

Installing .Net Framework 3.5 With out OS Image :

We can easy do that through group policy editor,

Go to gpedit.msc -> Administrative Templates -> Systems -> "Specify settings for optional Component Installation and component repair" to Enabled and Checking the box " Contact Update directly to download repair content instead of windows server update Services (WSUS) "

Once the options, Go to Command prompt and do gpdate /force

Then I start the .Net Framework installation from windows service

Migrating the Azure VM From One region to another region

Migrating the Azure VM From One region to another region

Setps & Steps to migrate azure VM from one region to another region :

1. Download & Install the AzCopy Utility Tool
2. We can easily move the VM from One region to another region. First, we need to create one storage account in destination region either it should be Premium or Standard account.
3. Get the Source OS disk blob Url, the url should looks like
 https://test.blob.core.windows.net:8080/vhds/test-os-7171.vhd... Go through on azure portal ->https://portal.azure.com ->Storage accounts ->storage accounts name -> blob Service -> get the blog url with container name
4. Same way get the other disks as well
Once get all those Information
5. Open the AzCopy Utility tool and paste the below command

AzCopy /Source:<https://sourceaccount.blob.core.windows.net/mycontainer1>  /Dest:https:<//destaccount.blob.core.windows.net/mycontainer2>  /SourceKey:<key1>  /DestKey:<key2> /Pattern:<abc.txt>).

Command Description :
<key1> --- Manage keys of Source Storage
<key2> ---- Manage keys of Designation Storage
<abc.txt> ---  test-os-7171.vhd (Path of C Drive)

Then copying transfer may start!!!! Do it all the disks

6. Once all the disks copied to another region, Important thing we need to create a disks from that
storage
7. Next step, We need to new Cloud Service in another region
8.Then start to spin up the VM, Go to portal https://portal.azure.com -> More Services -> search OS disks -> find out the
disks which had created from that storage account, then you can select the new cloud service and virtual network click
finish.

!!!! Now Server is created on another region!!!!!

Saturday, 17 September 2016

Solution for User Profile Service service failed the Sign-in user cannot be loaded on Windows Server 2012 Server

Solution for User Profile Service service failed the Sign-in user cannot be loaded on Windows Server 2012 Server

Today, I faced this error in one of my production Server, I went for google search to find this error but unfortunately couldn't get the solution.


I got from error message while  analysis on eventvwr inside that server,



Screenshot :








Then, I given full access to managed document folder, but no luck couldn't succeed.!!!!!!!!!!
Finally, I started compared with other windows 2012 server with same above mentioned path. Surprise!! there is no objects available inside the templates folders, then i compared some other servers, same no objects are available.

Then Confidently deleted whatever available inside that templates, then i tried login into my domain users, yes!! Successfully i can able to login it... :-)





Application Gateway Using Azure Power Shell

Application gateway using Azure PowerShell

Steps to configure the Application gateway

1. Download and Install the Azure windows power-shell
2. Add your azure azzount using this command : Add-AzureAccount
3. Once login into your account, get the azure Subscriptions whatever available in your azure account
Command : Get-AzureSubscription
4.Select the particular azure Subscription, from where those instances are available for configure the
application gateway
Command : Get-AzureSubscription
5.Next, We have to create a new application gateway using below command
Command : New-AzureApplicationGateway -Name AppGw -VnetName uvnet-Subnets @(Subnet-1")
6.Should be validate, the created application gateway
Command : Get-AzureApplicationGateway AppGw
7.Next Step, We need to create the SslCert
Command :  Add-AzureApplicationGatewaySslCertificate SslCert
8. The Step to add the application gateway certificate, We should copy our sslcertificate in
our local drive path for any name
Command : Add-AzureApplicationGatewaySslCertificate  -Name AppGw -CertificateName SslCert -Password
password -CertificateFile d:/mention the ssl certificate copied path here
9.Validate the application gateway SslCertificate
Command : Get-AzureApplicationGatewaySslCertificate AppGw
you may get the Output like this

VERBOSE: 12:10:26 PM - Begin Operation: Get-AzureApplicationGatewaySslCertificate
VERBOSE: 12:10:29 PM - Completed Operation: Get-AzureApplicationGatewaySslCertificate


Name           : SslCert
SubjectName    : CN=*.test.com, OU=tesct Sys, O=Test Sys Ltd, L=Chennai, S=Tamil Nadu, C=IN
Thumbprint     : DBAA15446ACF788BEA2CA555CFB69C69ECA09293
ThumbprintAlgo : sha256RSA
State          : Provisioned
10.Then, we have configure the Configfile of application gateway

Below, I'm Sharing the sample xml fle for configuring the xml depends on your requirement, Can configure http, https listeners etc.

<ApplicationGatewayConfiguration xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<FrontendIPConfigurations>
<Name>fep1</Name>
<Port>80</Port>
<FrontendPort>
</FrontendPort>
<FrontendPorts>
</FrontendPorts>
<Name>pool1</Name>
<IPAddress>10.0.0.1</IPAddress>
<IPAddress>10.0.0.2</IPAddress>
<IPAddresses>
</IPAddresses>
<BackendAddressPool>
</BackendAddressPool>
<BackendAddressPools>
</BackendAddressPools>
<Name>setting1</Name>
<Port>80</Port>
<Protocol>Http</Protocol>
<CookieBasedAffinity>Enabled</CookieBasedAffinity>
<BackendHttpSettings>
</BackendHttpSettings>
<BackendHttpSettingsList>
</BackendHttpSettingsList>
<Name>listener1</Name>
<FrontendPort>port1</FrontendPort>
<Protocol>Http</Protocol>
<HttpListener>
</HttpListener>
<HttpListeners>
</HttpListeners>
<Name>rule1</Name>
<Type>Basic</Type>
<BackendHttpSettings>setting1</BackendHttpSettings>
<Listener>listener1</Listener>
<BackendAddressPool>pool1</BackendAddressPool>
<HttpLoadBalancingRule>
</HttpLoadBalancingRule>
<HttpLoadBalancingRules>
</HttpLoadBalancingRules>
</FrontendIPConfigurations>
</ApplicationGatewayConfiguration>

Once modifying the xml file, copied in to local drive path same as Certificate path.

11. Next Step, we should create config file using created config.xml file
Command : Set-AzureApplicationGatewayConfig -Name AppGw -ConfigFile c:/Mention the config.xml drive path

12. Atlast, we finished all the steps for configuring the application gateway. Then we need to start our application gateway

Command : Start-AzureApplicationGateway AppGw

13. Final Step, we have get the azure application gateway

Command : Get-AzureApplicationGateway AppGw

Tuesday, 13 September 2016

Get Local Administrators using PowerShell

Copy & Paste the below powershell script in Windows Powershell

Function Get-LocalGroup  {

  [Cmdletbinding()]

  Param(

  [Parameter(ValueFromPipeline=$True, ValueFromPipelineByPropertyName=$True)]

  [String[]]$Computername =  $Env:COMPUTERNAME,

  [parameter()]

  [string[]]$Group

  )

  Begin {

  Function  ConvertTo-SID {

  Param([byte[]]$BinarySID)

  (New-Object  System.Security.Principal.SecurityIdentifier($BinarySID,0)).Value

}
        Function  Get-LocalGroupMember {

  Param  ($Group)

  $group.Invoke('members')  | ForEach {

  $_.GetType.Invoke().InvokeMember("Name",'GetProperty', $null, $_, $null)

  }

  }

  }

  Process  {

  ForEach  ($Computer in  $Computername) {

  Try  {

  Write-Verbose  "Connecting to $($Computer)"

  $adsi  = [ADSI]"WinNT://$Computer"

  If  ($PSBoundParameters.ContainsKey('Group')) {

  Write-Verbose  "Scanning for groups: $($Group -join ',')"

  $Groups  = ForEach  ($item in  $group) {                       

  $adsi.Children.Find($Item, 'Group')

  }

  } Else  {

  Write-Verbose  "Scanning all groups"

  $groups  = $adsi.Children | where {$_.SchemaClassName -eq  'group'}

  }

  If  ($groups) {

  $groups  | ForEach {

  [pscustomobject]@{

  Computername = $Computer

  Name = $_.Name[0]

  Members = ((Get-LocalGroupMember  -Group $_))  -join ', '

  SID = (ConvertTo-SID -BinarySID $_.ObjectSID[0])

  }

  }

  } Else  {

  Throw  "No groups found!"

  }

  } Catch  {

  Write-Warning  "$($Computer): $_"

  }

  }

  }

  }

Then, Mentioned the computer names which you want to get the users list from administrator groups and then save the txt file

In powershell ->  $Computers = Get-Content C:\Computers.txt

Then, using the below script, you can get the local admin users with format

Get-LocalGroup -Computername $computers -Group  Administrators | Select ComputerName, Name, Members | Format-Table -AutoSize