-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommands.txt
67 lines (45 loc) · 2.74 KB
/
Commands.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
Find-AzureRmResource -ResourceNameContains Callahan
Get-AzureRMSubscriptions
#RDA Stuff
$labStorageAccountName = 'callahanutility'
$labStorageAccountRG = 'CallahanUtility'
$vhdFileName = 'TestVM.vhd'
$labStorageAccountKey = (Get-AzureRMStorageAccountKey -StorageAccountName $labStorageAccountName -ResourceGroupName $labStorageAccountRG).key1
$vm = Find-AzureRmResource -ResourceNameContains Insite -ResourceType Microsoft.Compute/VirtualMachines
$resourceType = 'Microsoft.Compute/virtualMachines'
$properties = (Get-AzureRMResource -ResourceType $resourceType -ResourceName $vm.ResourceName -ResourceGroupName $vm.ResourceGroupName).Properties
$sourceUri = $properties.storageProfile.osDisk.vhd.uri
$uri = New-Object System.Uri($sourceUri)
$vmStorageAccountName = $uri.Host.Split('.')[0]
$storageAccounts = Find-AzureRmResource -ResourceType 'Microsoft.Storage/storageAccounts'
foreach($storageAccount in $storageAccounts){
if($storageAccount.ResourceName -eq $vmStorageAccountName){
$vmStorageAccountRG = $storageAccount.ResourceGroupName
}
}
$vmStorageAccountKey = (Get-AzureRMStorageAccountKey -StorageAccountName $vmStorageAccountName -ResourceGroupName $vmStorageAccountRG).key1
$srcContext = New-AzureStorageContext –StorageAccountName $vmStorageAccountName -StorageAccountKey $vmStorageAccountKey
$destContext = New-AzureStorageContext –StorageAccountName $labStorageAccountName -StorageAccountKey $labStorageAccountKey
$copyHandle = Start-AzureStorageBlobCopy -srcUri $sourceUri -SrcContext $srcContext -DestContainer 'vhdimages' -DestBlob $vhdFileName -DestContext $destContext -Force
#Recreate VM
$osDiskName = 'TestVM.vhd'
$nicName = 'testvm263'
$vmName = 'TestVMClone'
$vmSize = 'Standard_DS11'
$dcResourceGroupName = 'AZ_east'
$dcSubnetName = 'Development'
$resourceGroupName = 'CallahanUtility'
$username = 'callahant'
$password = 'somePassword1234'
# Get Network Interface Info
$nic = (Get-AzureRmNetworkInterface -ResourceGroupName $resourceGroupName | where { $_.Name -eq $nicName })
# Create credentials
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
$cred = New-Object System.Management.Automation.PSCredential ($username, $securePassword);
$vm = New-AzureRMVMConfig -VMName $vmName -vmSize $vmSize
# Cannot use Set-AzureRMVMOperatingSystem below when creating a VM from a VHD file copy
##$vm = Set-AzureRMVMOperatingSystem -VM $vm -Windows -ComputerName $vmName -Credential $cred -ProvisionVMAgent -EnableAutoUpdate
$vm = Add-AzureRMVMNetworkInterface -VM $vm -Id $nic.Id
$osDiskUri = $destContext.BlobEndPoint.ToString() + "vhdimages/" + $osDiskName
$vm = Set-AzureRMVMOSDisk -VM $vm -Name $vmName -VhdUri $osDiskUri -CreateOption Attach -Windows
New-AzureRmVM -ResourceGroupName $resourceGroupName -Location 'eastus' -VM $vm