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

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

Create virtual machines with the Azure PowerShell

Create a virtual machine

Virtual machines in Azure have a large number of dependencies. The Azure PowerShell creates these resources for you based on the command-line arguments you specify. For readability, we are using PowerShell splatting to pass parameters to the Azure PowerShell cmdlets.

Create a new virtual machine running Windows.

Azure PowerShell
$vmParams = @{
  ResourceGroupName = 'TutorialResources'
  Name = 'TutorialVM1'
  Location = 'eastus'
  ImageName = 'Win2016Datacenter'
  PublicIpAddressName = 'tutorialPublicIp'
  Credential = $cred
  OpenPorts = 3389
  Size = 'Standard_D2s_v3'
}
$newVM1 = New-AzVM @vmParams

As the VM is created, you see the parameter values used and Azure resources being created. PowerShell will display a progress bar as shown below.

Output
 Creating Azure resources
  39% \
  [ooooooooooooooooooooooooooooooooooo                                                                 ]

  Creating TutorialVM1 virtual machine.

Once the VM is ready, we can view the results in the Azure Portal or by inspecting the $newVM1 variable.

Azure PowerShell
$newVM1
Output
ResourceGroupName : TutorialResources
Id                : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/TutorialResources/providers/Microsoft.Compute/virtualMachines/TutorialVM1
VmId              : 00000000-0000-0000-0000-000000000000
Name              : TutorialVM1
Type              : Microsoft.Compute/virtualMachines
Location          : eastus
Tags              : {}
HardwareProfile   : {VmSize}
NetworkProfile    : {NetworkInterfaces}
OSProfile         : {ComputerName, AdminUsername, WindowsConfiguration, Secrets}
ProvisioningState : Succeeded
StorageProfile    : {ImageReference, OsDisk, DataDisks}

Property values listed inside of braces are nested objects. In the next step we will show you how to view specific values in these nested objects.

Try the code in your browser