Skip to content

Commit 5750edb

Browse files
committed
acrolinx and cleaned up powershell code
1 parent eb0f46d commit 5750edb

File tree

1 file changed

+70
-21
lines changed

1 file changed

+70
-21
lines changed

articles/virtual-network/ip-services/virtual-networks-static-private-ip-classic-ps.md

Lines changed: 70 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.service: virtual-network
77
ms.subservice: ip-services
88
ms.topic: how-to
99
ms.workload: infrastructure-services
10-
ms.date: 02/02/2016
10+
ms.date: 03/22/2023
1111
ms.author: allensu
1212
ms.custom: H1Hack27Feb2017
1313
---
@@ -24,13 +24,19 @@ This article covers the classic deployment model. You can also [manage a static
2424

2525
[!INCLUDE [virtual-networks-static-ip-scenario-include](../../../includes/virtual-networks-static-ip-scenario-include.md)]
2626

27-
The sample PowerShell commands below expect a simple environment already created. If you want to run the commands as they are displayed in this document, first build the test environment described in [Create a VNet](/previous-versions/azure/virtual-network/virtual-networks-create-vnet-classic-netcfg-ps).
27+
The following sample PowerShell commands expect a simple environment already created. If you want to run the commands as they're displayed in this document, first build the test environment described in [Create a VNet](/previous-versions/azure/virtual-network/virtual-networks-create-vnet-classic-netcfg-ps).
2828

2929
## How to verify if a specific IP address is available
30+
3031
To verify if the IP address *192.168.1.101* is available in a VNet named *TestVNet*, run the following PowerShell command and verify the value for *IsAvailable*:
3132

3233
```azurepowershell
33-
Test-AzureStaticVNetIP –VNetName TestVNet –IPAddress 192.168.1.101
34+
$tstip = @{
35+
VNetName = "TestVNet"
36+
IPAddress = "192.168.1.101"
37+
}
38+
Test-AzureStaticVNetIP @tstip
39+
3440
```
3541

3642
Expected output:
@@ -44,16 +50,42 @@ OperationStatus : Succeeded
4450
```
4551

4652
## How to specify a static private IP address when creating a VM
47-
The PowerShell script below creates a new cloud service named *TestService*, then retrieves an image from Azure, creates a VM named *DNS01* in the new cloud service using the retrieved image, sets the VM to be in a subnet named *FrontEnd*, and sets *192.168.1.7* as a static private IP address for the VM:
53+
54+
The following PowerShell script creates a new cloud service named *TestService*. The script then retrieves an image from Azure and creates a VM named *DNS01* in the new cloud service. Finally, the script using the sets the VM to be in a subnet named *FrontEnd*, and sets *192.168.1.7* as a static private IP address for the VM:
55+
4856

4957
```azurepowershell
50-
New-AzureService -ServiceName TestService -Location "Central US"
58+
$azsrv = @{
59+
ServiceName = "TestService"
60+
Location = "Central US"
61+
}
62+
New-AzureService @azsrv
63+
5164
$image = Get-AzureVMImage | where {$_.ImageName -like "*RightImage-Windows-2012R2-x64*"}
52-
New-AzureVMConfig -Name DNS01 -InstanceSize Small -ImageName $image.ImageName |
53-
Add-AzureProvisioningConfig -Windows -AdminUsername adminuser -Password MyP@ssw0rd!! |
54-
Set-AzureSubnet –SubnetNames FrontEnd |
55-
Set-AzureStaticVNetIP -IPAddress 192.168.1.7 |
56-
New-AzureVM -ServiceName TestService –VNetName TestVNet
65+
66+
$azcfg = @{
67+
Name = "DNS01"
68+
InstanceSize = "Small"
69+
ImageName = $image.ImageName
70+
}
71+
72+
$azprv = @{
73+
AdminUsername = "adminuser"
74+
}
75+
76+
$azsub = @{
77+
SubnetNames = "FrontEnd"
78+
}
79+
80+
$azip = @{
81+
IPAddress = "192.168.1.7"
82+
}
83+
84+
$azvm = @{
85+
ServiceName = "TestService"
86+
VNetsName = "TestVNet"
87+
}
88+
New-AzureVMConfig @azcfg | Add-AzureProvisioningConfig @azprv -Windows | Set-AzureSubnet @azsub | Set-AzureStaticVNetIP @azip | New-AzureVM @azvm
5789
```
5890

5991
Expected output:
@@ -67,10 +99,15 @@ New-AzureVM 3b99a86d-84f8-04e5-888e-b6fc3c73c4b9 Succeeded
6799
```
68100

69101
## How to retrieve static private IP address information for a VM
70-
To view the static private IP address information for the VM created with the script above, run the following PowerShell command and observe the values for *IpAddress*:
102+
103+
To view the static private IP address information for the VM created with the previous script, run the following PowerShell command and observe the values for *IpAddress*:
71104

72105
```azurepowershell
73-
Get-AzureVM -Name DNS01 -ServiceName TestService
106+
$vm = @{
107+
Name = "DNS01"
108+
ServiceName = "TestService"
109+
}
110+
Get-AzureVM @vm
74111
```
75112

76113
Expected output:
@@ -105,12 +142,15 @@ OperationStatus : OK
105142
```
106143

107144
## How to remove a static private IP address from a VM
108-
To remove the static private IP address added to the VM in the script above, run the following PowerShell command:
145+
146+
To remove the static private IP address added to the VM in the previous script, run the following PowerShell command:
109147

110148
```azurepowershell
111-
Get-AzureVM -ServiceName TestService -Name DNS01 |
112-
Remove-AzureStaticVNetIP |
113-
Update-AzureVM
149+
$vm = @{
150+
Name = "DNS01"
151+
ServiceName = "TestService"
152+
}
153+
Get-AzureVM -ServiceName @vm | Remove-AzureStaticVNetIP | Update-AzureVM
114154
```
115155

116156
Expected output:
@@ -122,12 +162,18 @@ Update-AzureVM 052fa6f6-1483-0ede-a7bf-14f91f805483 Succeeded
122162
```
123163

124164
## How to add a static private IP address to an existing VM
125-
To add a static private IP address to the VM created using the script above, run the following command:
165+
166+
To add a static private IP address to the VM created using the previous script, run the following command:
126167

127168
```azurepowershell
128-
Get-AzureVM -ServiceName TestService -Name DNS01 |
129-
Set-AzureStaticVNetIP -IPAddress 192.168.1.7 |
130-
Update-AzureVM
169+
$vm = {
170+
Name = "DNS01"
171+
ServiceName = "TestService"}
172+
173+
$ip = {
174+
IPAddress = "192.168.1.7"
175+
}
176+
Get-AzureVM @vm | Set-AzureStaticVNetIP @ip | Update-AzureVM
131177
```
132178

133179
Expected output:
@@ -140,9 +186,12 @@ Update-AzureVM 77d8cae2-87e6-0ead-9738-7c7dae9810cb Succeeded
140186

141187
## Set IP addresses within the operating system
142188

143-
It’s recommended that you do not statically assign the private IP assigned to the Azure virtual machine within the operating system of a VM, unless necessary. If you do manually set the private IP address within the operating system, ensure that it is the same address as the private IP address assigned to the Azure VM, or you can lose connectivity to the virtual machine. You should never manually assign the public IP address assigned to an Azure virtual machine within the virtual machine's operating system.
189+
It’s recommended that you don't statically assign the private IP assigned to the Azure virtual machine within the operating system of a VM, unless necessary. If you do manually set the private IP address within the operating system, ensure that it's the same address as the private IP address assigned to the Azure VM. Failure to match the IP address could result in loss of connectivity to the virtual machine.
144190

145191
## Next steps
192+
146193
* Learn about [reserved public IP](/previous-versions/azure/virtual-network/virtual-networks-reserved-public-ip) addresses.
194+
147195
* Learn about [instance-level public IP (ILPIP)](/previous-versions/azure/virtual-network/virtual-networks-instance-level-public-ip) addresses.
196+
148197
* Consult the [Reserved IP REST APIs](/previous-versions/azure/reference/dn722420(v=azure.100)).

0 commit comments

Comments
 (0)