Azure Powershell脚本:解析错误

时间:2016-02-17 14:32:18

标签: powershell azure azure-virtual-machine powershell-ise azure-powershell

尝试通过PowerShell设置新VM。我复制时工作正常将命令逐步粘贴到PowerShell ISE,但是当我尝试一次性运行它们时失败。

我已经删除了脚本的其他部分,它也只是失败了:

$VM_NAME         = "VMNAME"
$VM_SIZE         = "Small"
$VM_IMAGE        = "5112500ae3b842c8b9c604889f8753c3__OpenLogic-CentOS-71-20150605"
$LOCATION        = "West Europe"
$STORAGE_ACCOUNT = "disktest"
$CLOUD_SERVICE   = "disktest"
$SSH_USER        = "azureuser"
$SSH_PASSWORD    = "324w##eANC"
$VIRTUAL_NETWORK = "Playground"
$SUBNET          = "P"

$BOOTSTRAP_CHEF      = $FALSE
$PATH_PUBLIC_CONFIG  = "publicconfig.json"
$PATH_PRIVATE_CONFIG = "privateconfig.json"
$DISK_CREATE         = $TRUE
$DISK_SIZE           = 500
$DISK_COUNT          = 2
$DISK_LABEL          = "datadisk"
$DISK_LUN            = 0
$REMOVE_SSH_ENDPOINT = $FALSE
$HTTP_ENDPOINT       = $FALSE
$SHUTDOWN            = $FALSE

Select-AzureSubscription -SubscriptionName "SUB" -Current;

if (!(Test-AzureName -Storage $STORAGE_ACCOUNT)) {
    New-AzureStorageAccount -StorageAccountName $STORAGE_ACCOUNT -Location $LOCATION
}

if (!(Test-AzureName -Service $CLOUD_SERVICE)) {
    New-AzureService -ServiceName $CLOUD_SERVICE -Location $LOCATION
}

Set-AzureSubscription -SubscriptionName "SUB" -CurrentStorageAccountName $STORAGE_ACCOUNT

$existing = Get-AzureVM -ServiceName $CLOUD_SERVICE -Name $VM_NAME

错误讯息:

In Zeile:36 Zeichen:1
+ $existing = Get-AzureVM -ServiceName $CLOUD_SERVICE -Name $VM_NAME
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ausführbarer Skriptcode wurde im Signaturblock gefunden.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : TokenAfterEndOfValidScriptText

如果我首先设置变量,请从脚本窗口中删除它们,然后再次运行它就像魅力一样。

1 个答案:

答案 0 :(得分:0)

问题是“解决” - 几个小时后与微软交谈:这是PowerShell 3.0中与Windows 7结合的错误!

要解决此问题,请安装PowerShell 4.0,重新安装Azure PowerShell并重新启动工作站。