File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -203,6 +203,27 @@ $vm = Get-AzVM -ResourceGroupName $ResourceGroupName -Name $VMName -UserData;
203
203
204
204
The UserData value must always be Base64 encoded.
205
205
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
+
206
227
## PARAMETERS
207
228
208
229
### -AddressPrefix
You can’t perform that action at this time.
0 commit comments