简体   繁体   English

当我使用 Azure Powershell 创建新 VM 时,我没有获得公共 IP 地址。 为什么?

[英]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 Doc1Doc 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 :结果

使用 PowerShell 脚本创建 VM 以获取 PublicIP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Powershell使用高级存储和公共静态IP创建Azure VM - Create Azure VM with Premium Storage and Public Static IP Using Powershell 使用 powershell 在 Azure 中创建 VM,没有公共 IP - Create VM in Azure with powershell with no public IP 我如何通过python SDK从azure中的VM的公共IP地址获取实例ID /名称 - How do I get instance id/name from public ip address of VM in azure via python sdk 如何访问 Azure 中的故障转移虚拟机。 我没有看到公共 IP 地址。 这也是我的试用帐户 - how to access the failover virtual machine in Azure . I am not seeing the Public IP address. Also this is my trial account 如何获得我的Azure VM的公共IP? - How do I get a public IP for my Azure VM? 如何通过REST API使用公共IP地址创建Azure VM - How to create Azure VM with Public IP address through REST API 如何通过Powershell获取新创建的Azure VM的IP地址 - How to get the IP address of the newly created Azure VM via Powershell 如何在 azure 的不同位置使用公共 IP 地址和 VM? - How can I use Public IP address and VM in different locations in azure? 为什么不能使用java ..使用连接IP连接到运行带有公共IP的Windows Azure VM,但出现连接超时错误? - Why can`t I connect to Windows Azure VM running couchbase with public IP using java .. Getting Connection time out error? Azure Powershell (Az模块) 公开IP地址 - Azure Powershell (Az module) get public IP address
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM