#20190204 - 2nd comment, this one in master branch
#7th comment

# copy disk example
<#
set-azurermcontext -Subscription npd01
$disk = Get-AzureRmDisk -ResourceGroupName rg-doh-intranetconnections-tst -DiskName vm-itddohict1-app-tst-001
set-azurermcontext -Subscription prd01
$newdisk = New-AzureRmDiskConfig -SourceResourceId $disk.Id -Location centralus -CreateOption Copy
New-AzureRmDisk -ResourceGroupName rg-doh-intranetconnections-prd -DiskName vm-itddohicp1-app-prd-001 -Disk $newdisk
#>




$computername="itdadfsldt1"
#Provide the subscription Id
$subscriptionId = '76297098-764c-43de-8525-c9fda1b237be'

#Provide the name of your resource group
$resourceGroupName ='rg-infra-adfs-tst'

Set-AzureRmContext -Subscription infra01
$disk = Get-AzureRmDisk -ResourceGroupName $resourceGroupName -DiskName "dev_sda-vm_itdadfsldt1_tst"
Set-AzureRmContext -Subscription npd01
$newdisk = New-AzureRmDiskConfig -SourceResourceId $disk.Id -Location centralus -CreateOption Copy
New-AzureRmDisk -ResourceGroupName $resourceGroupName -DiskName vm-$computername-os-tst -Disk $newdisk

#Provide the name of the OS disk that will be created using the snapshot
$osDiskName = "vm-$computername-os-tst"

#Provide the name of the virtual machine
$virtualMachineName = "vm-$computername-tst"

$nicName = "nic-$computername-tst-101"

#Provide the size of the virtual machine
#e.g. Standard_DS3
#Get all the vm sizes in a region using below script:
#e.g. Get-AzureRmVMSize -Location westus
$virtualMachineSize = 'Standard_A1'

#Set the context to the subscription Id where Managed Disk will be created
#Select-AzureRmSubscription -SubscriptionId $SubscriptionId
Set-AzureRmContext -Subscription npd01
<#
$resourceGroupName="rg-doh-intranetconnections-prd"
$osDiskName="vm-itddohicp1-os-prd"
$virtualMachineName="vm-itddohicp1-prd"
$virtualMachineSize="Standard_B2ms"
$nicName="nic-itddohicp1-prd"
#>

$disk = Get-AzureRmDisk -ResourceGroupName $resourceGroupName -DiskName $osDiskName

#Initialize virtual machine configuration
$VirtualMachine = New-AzureRmVMConfig -VMName $virtualMachineName -VMSize $virtualMachineSize

#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 -ManagedDiskId $disk.Id -CreateOption Attach -Linux

$nic = Get-AzureRmNetworkInterface -ResourceGroupName $resourcegroupname -Name $nicName

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

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








Set-AzureRmContext -Subscription infra01
$disks = Get-AzureRmDisk -ResourceGroupName rg-infra-adfs-tst -ov npddisks
Set-AzureRmContext -Subscription npd01
ForEach($d in $disks)
{
    $newdisk=$null
    $computername=$null


    $computername = $d.name.split('_')[2]
    If($d.name -like "*sda*")
    {
        $newname = "vm-$computername-os-tst"
    }
    If($d.name -like "*sdb*")
    {
        $newname = "vm-$computername-app-tst-101"
        $newdisk = New-AzureRmDiskConfig -SourceResourceId $d.Id -Location centralus -createoption Copy
        New-AzureRmDisk -ResourceGroupName rg-infra-adfs-tst -DiskName $NewName -Disk $newdisk
    }
}
<#
$disk = Get-AzureRmDisk -ResourceGroupName rg-infra-adfs-tst -DiskName dev_sdb-vm_itdadfsintldt1_tst
set-azurermcontext -Subscription npd01
$newdisk = New-AzureRmDiskConfig -SourceResourceId $disk.Id -Location centralus -CreateOption Copy
New-AzureRmDisk -ResourceGroupName rg-infra-adfs-tst -DiskName vm-itdadfsldt1-app-tst-001 -Disk $newdisk
#>