[英]When I create a new VM using Azure Powershell I get no public IP Address. Why?
I just started playing around with Azure Powershell and I'm trying to create a new Azure VM.我刚开始使用 Azure Powershell,我正在尝试创建一个新的 Azure VM。
Script:脚本:
$username = 'demoadmin'
$password = ConvertTo-SecureString 'Password123!@#' -AsPlainText -Force
$WindowsCred = New-Object System.Management.Automation.PSCredential ($username, $password)
New-AzVM -ResourceGroup 'psdemo-rg-uksouth' -Name 'psdemo-win-az' -Image 'win2016datacenter' -Size 'Standard_D2ads_v5' -Credential $WindowsCred -OpenPorts 3389
Result: Azure VM is successfully created, but there is no Public IP address assigned.结果:已成功创建 Azure VM,但未分配公共 IP 地址。
Looking at the documentation here I can see the description for parameter "PublicIpAddressName": "The name of a new (or existing) public IP address for the created VM to use. If not specified, a name will be generated.".查看此处的文档,我可以看到参数“PublicIpAddressName”的描述:“创建的 VM 要使用的新(或现有)公共 IP 地址的名称。如果未指定,将生成一个名称。”。
How can I make it assign a Public IP Address on creation?如何让它在创建时分配公共 IP 地址?
When I run the PowerShell commands you provided, yes - it is not provisioned the Public IP address, but it will be assigned the Private IP Address by Azure dynamically.当我运行您提供的 PowerShell 命令时,是的 - 它没有配置公共 IP 地址,但 Azure 会动态为其分配私有 IP 地址。
If you do not pass the PublicIpAddressName parameter, then it will not be created automatically:如果不传递 PublicIpAddressName 参数,则不会自动创建:
Following these MSFT Doc1 & Doc 2 , we have to pass the Public IP Address parameter to get assigned to the associated Virtual Machine by Azure.在这些 MSFT Doc1和Doc 2之后,我们必须传递公共 IP 地址参数以由 Azure 分配给关联的虚拟机。
PowerShell Script I used to get the Public IP Address while VM Creation in Azure :我在 Azure 中创建 VM 时用于获取公共 IP 地址的 PowerShell 脚本:
#Create the Virtual Network
$vnet = @{
Name = 'myVNet'
ResourceGroupName = 'HariTestRg'
Location = 'EastUS'
AddressPrefix = '10.0.0.0/16'
}
$virtualNetwork = New-AzVirtualNetwork @vnet
#Create the Subnet
$subnet = @{
Name = 'default'
VirtualNetwork = $virtualNetwork
AddressPrefix = '10.0.0.0/24'
}
$subnetConfig = Add-AzVirtualNetworkSubnetConfig @subnet
$virtualNetwork | Set-AzVirtualNetwork
#Create the Virtual Machine by passing the Public IP Address parameter
$username = '<your-user-name>'
$password = ConvertTo-SecureString '<your-password>' -AsPlainText -Force
$WindowsCred = New-Object System.Management.Automation.PSCredential ($username, $password)
New-AzVm `
-ResourceGroupName "HariTestRg" `
-Name "psdemo-win-az02" `
-Location "EastUS" `
-VirtualNetworkName "myVnet" `
-SubnetName "default" `
-SecurityGroupName "myNetworkSecurityGroup" `
-PublicIpAddressName "myPublicIpAddress2" `
-ImageName "MicrosoftWindowsServer:WindowsServer:2016-Datacenter-with-Containers:latest" `
-Credential $WindowsCred
Result :结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.