Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Powershell在Azure中创建VM_Powershell_Azure - Fatal编程技术网

使用Powershell在Azure中创建VM

使用Powershell在Azure中创建VM,powershell,azure,Powershell,Azure,我正在尝试使用powershell在Azure中创建VM。我正在本地PC上运行此程序。我已经能够设置网站和SQL Azure实例,没有任何问题,但web上的任何示例都无法工作 Import-Module Azure Import-AzurePublishSettingsFile -PublishSettingsFile "C:\Cloud\Azure.publishsettings" $VMImage = @(Get-AzureVMImage | Where-Object -Property

我正在尝试使用powershell在Azure中创建VM。我正在本地PC上运行此程序。我已经能够设置网站和SQL Azure实例,没有任何问题,但web上的任何示例都无法工作

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服务,或者将新虚拟机部署到现有服务中


我刚刚添加了location参数,效果很好

最后,我添加了一个关联组,并更改了我使用的服务名称。这使我能够创建虚拟机。据我在订阅中所知,我使用的服务名称未被使用,因此之前的安装失败留下了一些瑕疵,或者名称需要全局唯一。我查过这里的文件了
并且它没有说明服务名称必须是全局唯一的

将值分配/替换为变量

New AzureVMConfig-Name$VmName-InstanceSize$InstanceSize-Label$VmName-ImageName$ImageName-DiskLabel$DiskLabel |
添加azureprovisioningconfig-LinuxUser$cred.GetNetworkCredential().用户名-Linux-密码$cred.GetNetworkCredential().密码-SSHPublicKeys$sshkey |
添加AzureEndpoint-LocalPort$LocalPort1-Name$LocalPortName1-Protocol tcp-PublicPort$LocalPort1 |
新AzureVM-ServiceName$CloudServiceName-AffinityGroup$AffinityGroup–WaitForBoot

您好,我根据您的建议对上述内容进行了一些编辑。感谢服务名称绝对应该是全局唯一的,因为它是DNS名称(*.cloudapp.net)
新AzureQuickVM将检查云服务是否存在,如果存在,它将使用其他方法尝试创建。但是,当它试图创建它时,如果没有指定关联组或位置,它将失败,这可能就是你的脚本发生的情况。我看到了同样的问题,这篇文章确实非常有用。谢谢你。请记住,除了添加-Location参数外,还需要更改ServiceName。没有更改ServiceName,我的命令继续失败。非常不直观&很可能是一个azure bug。