Skip to content

Commit 1f8a726

Browse files
authored
Added example for New-AzVM
* Example 4: Create a new VM in a ResourceGroup1 with existing Subnet (in ResourceGroup 2) $UserName = "User" $Password = ConvertTo-SecureString "############" -AsPlainText -Force $psCred = New-Object System.Management.Automation.PSCredential($UserName, $Password) $Vnet = $(Get-AzVirtualNetwork -ResourceGroupName ResourceGroup2 -Name VnetName) $PIP = (Get-AzPublicIpAddress -ResourceGroupName ResourceGroup2 -Name PublicIPName) $NIC = New-AzNetworkInterface -Name NICname -ResourceGroupName ResourceGroup2 -Location SouthCentralUS -SubnetId $Vnet.Subnets[1].Id -PublicIpAddressId $PIP.Id $VirtualMachine = New-AzVMConfig -VMName VirtualMachineName -VMSize Standard_D4s_v3 $VirtualMachine = Set-AzVMOperatingSystem -VM $VirtualMachine -Windows -ComputerName computerName -Credential $psCred -ProvisionVMAgent -EnableAutoUpdate $VirtualMachine = Add-AzVMNetworkInterface -VM $VirtualMachine -Id $NIC.Id $VirtualMachine = Set-AzVMSourceImage -VM $VirtualMachine -PublisherName 'MicrosoftWindowsServer' -Offer 'WindowsServer' -Skus '2012-R2-Datacenter' -Version latest New-AzVm -ResourceGroupName ResourceGroup1 -Location SouthCentralUS -VM $VirtualMachine * Update New-AzVM.md
1 parent 17c62f7 commit 1f8a726

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/Compute/Compute/help/New-AzVM.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,27 @@ $vm = Get-AzVM -ResourceGroupName $ResourceGroupName -Name $VMName -UserData;
203203

204204
The UserData value must always be Base64 encoded.
205205

206+
207+
### Example 4: Creating a New VM in RG1 with an existing subnet in RG2
208+
```
209+
$UserName = "User"
210+
$Password = ConvertTo-SecureString "############" -AsPlainText -Force
211+
$psCred = New-Object System.Management.Automation.PSCredential($UserName, $Password)
212+
213+
$Vnet = $(Get-AzVirtualNetwork -ResourceGroupName ResourceGroup2 -Name VnetName)
214+
$PIP = (Get-AzPublicIpAddress -ResourceGroupName ResourceGroup2 -Name PublicIPName)
215+
216+
$NIC = New-AzNetworkInterface -Name NICname -ResourceGroupName ResourceGroup2 -Location SouthCentralUS -SubnetId $Vnet.Subnets[1].Id -PublicIpAddressId $PIP.Id
217+
$VirtualMachine = New-AzVMConfig -VMName VirtualMachineName -VMSize Standard_D4s_v3
218+
$VirtualMachine = Set-AzVMOperatingSystem -VM $VirtualMachine -Windows -ComputerName computerName -Credential $psCred -ProvisionVMAgent -EnableAutoUpdate
219+
$VirtualMachine = Add-AzVMNetworkInterface -VM $VirtualMachine -Id $NIC.Id
220+
$VirtualMachine = Set-AzVMSourceImage -VM $VirtualMachine -PublisherName 'MicrosoftWindowsServer' -Offer 'WindowsServer' -Skus '2012-R2-Datacenter' -Version latest
221+
New-AzVm -ResourceGroupName ResourceGroup1 -Location SouthCentralUS -VM $VirtualMachine
222+
```
223+
224+
This example deploys a Windows VM from the marketplace in one resource group with an existing subnet in another resource group.
225+
226+
206227
## PARAMETERS
207228

208229
### -AddressPrefix

0 commit comments

Comments
 (0)