Прочетете на английски Редактиране

Споделяне чрез

Create virtual machines with the Azure PowerShell

Get VM information with queries

Let's get some more detailed information from the VM we just created. In this example, we verify the Name of the VM and the admin account we created.

Azure PowerShell
$newVM1.OSProfile | Select-Object -Property ComputerName, AdminUserName
Output
ComputerName AdminUsername
------------ -------------
TutorialVM1  tutorialAdmin

We can use other Azure PowerShell commands to get specific information about the network configuration.

Azure PowerShell
$newVM1 | Get-AzNetworkInterface |
  Select-Object -ExpandProperty IpConfigurations |
    Select-Object -Property Name, PrivateIpAddress

In this example we are using the PowerShell pipeline to send the $newVM1 object to the Get-AzNetworkInterface cmdlet. From the resulting network interface object we are selecting the nested IpConfigurations object. From the IpConfigurations object we are selecting the Name and PrivateIpAddress properties.

Output
Name        PrivateIpAddress
----        ----------------
TutorialVM1 192.168.1.4

To confirm that the VM is running, we need to connect via Remote Desktop. For that, we need to know the Public IP address.

Azure PowerShell
$publicIp = Get-AzPublicIpAddress -Name tutorialPublicIp -ResourceGroupName TutorialResources

$publicIp |
  Select-Object -Property Name, IpAddress, @{label='FQDN';expression={$_.DnsSettings.Fqdn}}

In this example, we use the Get-AzPublicIpAddress and store the results in the $publicIp variable. From this variable we are selecting properties and using an expression to retrieve the nested Fqdn property.

Output
Name             IpAddress           FQDN
----             ---------           ----
tutorialPublicIp <PUBLIC_IP_ADDRESS> tutorialvm1-8a0999.eastus.cloudapp.azure.com

From your local machine you can run the following command to connect to the VM over Remote Desktop.

PowerShell
mstsc.exe /v $publicIp.IpAddress

For more information about querying for object properties, see Querying for Azure resources.

Try the code in your browser