我正在尝试使用 powershell 在 Azure 中创建 VM。我正在本地 PC 上运行它。我已经能够设置网站和 SQL Azure 实例,没有任何问题,但网络上的示例都不起作用。
Import-Module Azure
Import-AzurePublishSettingsFile -PublishSettingsFile "C:\Cloud\Azure.publishsettings"
$VMImage = @(Get-AzureVMImage | Where-Object -Property Label -Match "Windows Server 2012 R2 Datacenter, November 2014").ImageName
$myVMName = "jsTestVM1"
$myAdminName ="jsTestAdmin1"
$myAdminPwd ="not telling you"
New-AzureQuickVM -ImageName $VMImage -Windows -Name $myVMName -ServiceName $myVMName -AdminUsername $myAdminName -Password $myAdminPwd -InstanceSize "ExtraSmall"
我收到以下消息:
New-AzureQuickVM : ResourceNotFound: The hosted service does not exist.
At line:1 char:1
+ New-AzureQuickVM -ImageName $VMImage -Windows -Name $myVMName -ServiceName $myVM ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureQuickVM], CloudException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.PersistentVMs.NewQuickVM
我尝试了网络上的示例,它们也给出了相同的错误消息。
编辑:
如果我指定位置,则会收到错误消息“服务已存在,无法指定位置”。 如果我指定 AffinityGroup,我会收到“服务已存在,无法指定 AffinityGroup”
最佳答案
$VMImage = @(Get-AzureVMImage | Where-Object -Property Label -Match "Windows Server 2012 R2 Datacenter, November 2014").ImageName
$myVMName = "srikstest"
$myAdminName ="srikstest"
$myAdminPwd ="NeitherMe"
New-AzureQuickVM -Windows -ServiceName $myVMName -ImageName $VMImage -AdminUsername $myAdminName - Password $myAdminPwd -InstanceSize "ExtraSmall" -Location "Southeast Asia" -Name $myVMName -Verbose
您可以通过指定 Location 或 AffinityGroup 参数为虚拟机创建新的 Azure 服务,或者将新虚拟机部署到现有服务中。
我刚刚添加了位置参数并且它起作用了!!
关于powershell - 使用 Powershell 在 Azure 中创建 VM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27530596/