$resourceGroupName = ‘cloud-shell-storage-southeastasia’
$location = ‘Brazil South’
$vmName = ‘ffdts20180904’
$snapshotName = ‘mySnapshot’

$vm = get-azurermvm -ResourceGroupName $resourceGroupName -Name $vmName
$snapshot = New-AzureRmSnapshotConfig -SourceUri $vm.StorageProfile.OsDisk.ManagedDisk.Id -Location $location -CreateOption copy

New-AzureRmSnapshot -Snapshot $snapshot -SnapshotName $snapshotName -ResourceGroupName $resourceGroupName

$snapshotName = ‘mySnapshotDataDisk’
$disk=$vm.StorageProfile.DataDisks| Select-Object -first 1
$snapshot = New-AzureRmSnapshotConfig -SourceUri $disk.ManagedDisk.Id -Location $location -CreateOption copy
New-AzureRmSnapshot -Snapshot $snapshot -SnapshotName $snapshotName -ResourceGroupName $resourceGroupName

$noOfVMsToCreate = 9
$startingVMNumber = 2

$vmPreFix = “fdts20180904-”

$resourceGroupName =’cloud-shell-storage-southeastasia’
$availSet = Get-AzureRmAvailabilitySet -ResourceGroupName $resourceGroupName -Name ‘FF’
$snapshotName = ‘mySnapshot’
$snapshotName2 = ‘mySnapshotDataDisk’

for($i = 1; $i -le $noOfVMsToCreate; $i++){

#Provide the name of the OS disk that will be created using the snapshot
$osDiskName = $vmPreFix + $startingVMNumber + ‘-OSDisk’
$dataDiskName = $vmPreFix + $startingVMNumber + ‘-DataDisk’

#Provide the name of an existing virtual network where virtual machine will be created
$virtualNetworkName = ‘FFBR-vnet’

#Provide the name of the virtual machine
$virtualMachineName = $vmPreFix + $startingVMNumber

$virtualMachineSize = ‘Standard_D32s_v3′

$snapshot = Get-AzureRmSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName
$diskConfig = New-AzureRmDiskConfig -Location $snapshot.Location -SourceResourceId $snapshot.Id -CreateOption Copy
$disk = New-AzureRmDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $osDiskName

$snapshot2 = Get-AzureRmSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName2
$diskConfig2 = New-AzureRmDiskConfig -Location $snapshot2.Location -SourceResourceId $snapshot2.Id -CreateOption Copy
$dataDisk1 = New-AzureRmDisk -Disk $diskConfig2 -ResourceGroupName $resourceGroupName -DiskName $dataDiskName

#Initialize virtual machine configuration
$VirtualMachine = New-AzureRmVMConfig -VMName $virtualMachineName -VMSize $virtualMachineSize -AvailabilitySetId $availSet.Id

#Use the Managed Disk Resource Id to attach it to the virtual machine. Please change the OS type to linux if OS disk has linux OS
$VirtualMachine = Set-AzureRmVMOSDisk -VM $VirtualMachine -DiskName $osDiskName -ManagedDiskId $disk.Id -CreateOption Attach -Linux

#add the datadisk
$VirtualMachine = Add-AzureRmVMDataDisk -VM $VirtualMachine -Name $dataDiskName -CreateOption Attach -ManagedDiskId $dataDisk1.Id -Lun 0

#Create a public IP for the VM
$publicIp = New-AzureRmPublicIpAddress -Name ($VirtualMachineName.ToLower()+’_ip’) -ResourceGroupName $resourceGroupName -Location $snapshot.Location -AllocationMethod Dynamic

#Get the virtual network where virtual machine will be hosted
$vnet = Get-AzureRmVirtualNetwork -Name $virtualNetworkName -ResourceGroupName $resourceGroupName

# Create NIC in the first subnet of the virtual network
$nic = New-AzureRmNetworkInterface -Name ($VirtualMachineName.ToLower()+’_nic’) -ResourceGroupName $resourceGroupName -Location $snapshot.Location -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $publicIp.Id

$VirtualMachine = Add-AzureRmVMNetworkInterface -VM $VirtualMachine -Id $nic.Id

#Create the virtual machine with Managed Disk
New-AzureRmVM -VM $VirtualMachine -ResourceGroupName $resourceGroupName -Location $snapshot.Location

$startingVMNumber=$startingVMNumber+1

}