【问题标题】:A positional parameter cannot be found that accepts argument when running New-AzureQuickVM运行 New-AzureQuickVM 时找不到接受参数的位置参数
【发布时间】:2015-04-23 22:20:31
【问题描述】:

我有以下 PowerShell 脚本:

 Param(  
       $AccountName = "AccountName",
       $Guid = "Get-Random",
       $ImageName = "ImageName",
       $vmName = "VM-$Guid",
       $ServiceName = "ServiceName",
       $adminLogin = "adminLogin",
       $adminPasswd = "adminPasswd!",
       $location = "South Central US",
       $instanceSize = "Medium",
       $subscriptionDataFile = "file.publishsettings"
        )
    ########################Import Azure Public Setting And Assign Storage###########################
    Import-AzurePublishSettingsFile $subscriptionDataFile 
    Set-AzureSubscription -SubscriptionName $AccountName -CurrentStorageAccountName scrprod -PassThru

    #########################Create A VM From Existing Image And Remove It##########################


    for($i=1; $i -le 5; $i++)
    {
    New-AzureQuickVM –Windows –Location $location –ServiceName $ServiceName `
     –Name $vmName –InstanceSize $InstanceSize –ImageName $ImageName–AdminUsername $adminLogin –Password $adminPasswd -WaitForBoot 
    })

我得到以下异常: New-AzureQuickVM:找不到接受参数“‘Windows’Location’的位置参数。

我做错了什么?

其次,我想创建 5 个具有唯一名称的虚拟机 - 这是正确的做法吗?

谢谢,

奥伦

【问题讨论】:

    标签: powershell azure


    【解决方案1】:

    我认为您的文本文件的编码不正确,或者您使用了不正确的字符(可能来自剪切和粘贴)。

    你的代码

    New-AzureQuickVM –Windows –Location
    

    以某种方式被评估为

    New-AzureQuickVM 'â€Windows â€Location'
    

    我建议删除WindowsLocation 之前的- 字符(可能还有其他地方),然后重新输入。还要检查文件的编码和字符集。

    【讨论】:

    • 好声音,我最近遇到了这个问题,当我将脚本和使用说明通过电子邮件发送给某人时,我将一个脚本的语法从 ISE 复制到了 Outlook,Outlook 损坏了它!
    • 是的。 Outlook更改了编码。谢谢。
    【解决方案2】:

    在调用 New-AzureQuickVM cmdlet 时出现格式错误,最明显的是$ServiceName 之后的反引号如果不紧跟新行可能会导致问题。另外,$ImageName-AdminUsername 之间应该有一个空格。

    按照 guid 的条款,我会使用 $guid = ([guid]::NewGuid()).ToString() 创建一个,但实际上随机的定义取决于您。

    【讨论】:

      猜你喜欢
      • 2016-07-06
      • 2014-09-30
      • 1970-01-01
      • 1970-01-01
      • 2015-05-21
      • 2019-12-23
      • 1970-01-01
      相关资源
      最近更新 更多