在表达式或语句中获取意外标记')'. [英] Getting the Unexpected token ')' in expression or statement.

查看:189
本文介绍了在表达式或语句中获取意外标记')'.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很生气,每当发生这种情况时,我现在都可以尖叫!每次将ANY代码添加到以下自动化命令中时,在测试时都会收到以下消息;

I am so furious I could scream right now, every single time this happens! Every time I add ANY code to the following automation command, I get the following message when Testing;

+ )

+ ~
Unexpected token ')' in expression or statement.

它不知道这是哪行,也不是用简单的英语,所以我什至无法解决不存在"的问题.问题.这是一个愚蠢的系统.

It gives me no clue as to which line this is, nor is it in plain English so I can't even fix the "non-existent" problem. It's a stupidly-designed system.

param (
  
    [Parameter(Mandatory=$false)] 
    [String] $VMName 
 
    [Parameter(Mandatory=$false)] 
    [String] $ResourceGroupName

    #[Parameter(Mandatory=$false)]
    #[String] $SubscriptionId
    
)
 
$connectionName = "AzureRunAsConnection"
try
{
    # Get the connection "AzureRunAsConnection "
    $servicePrincipalConnection=Get-AutomationConnection -Name $connectionName         
 
    "Logging in to Azure..."
    Add-AzureRmAccount `
        -ServicePrincipal `
        -TenantId $servicePrincipalConnection.TenantId `
        -ApplicationId $servicePrincipalConnection.ApplicationId `
        -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint 
}
catch {
    if (!$servicePrincipalConnection)
    {
        $ErrorMessage = "Connection $connectionName not found."
        throw $ErrorMessage
    } else{
        Write-Error -Message $_.Exception
        throw $_.Exception
    }
}
 
 
# If there is a specific resource group, then get all VMs in the resource group,
# otherwise get all VMs in the subscription.
if ($ResourceGroupName -And $VMName) 
{ 
    $VMs = Get-AzureRmVM -ResourceGroupName $ResourceGroupName -Name $VMName
}
elseif ($ResourceGroupName)
{
    $VMs = Get-AzureRmVM -ResourceGroupName $ResourceGroupName
 
}
else 
{ 
    $VMs = Get-AzureRmVM
}
# Start each of the VMs
foreach ($VM in $VMs)
{
   
    
            $StartRtn = $VM | Start-AzureRmVM -ErrorAction Continue
            $StartRtn
            Write-Output "This is $StartRtn"
 
            if ($StartRtn.IsSuccessStatusCode -eq 'True')
            {
                # The VM started, so send notice
                Write-Output ($VM.Name + " has started successfully")
                $Username ="xxxx"

                $Password = ConvertTo-SecureString "xxx" -AsPlainText -Force

                $credential = New-Object System.Management.Automation.PSCredential $Username, $Password

                $SMTPServer = "smtp.sendgrid.net"

                $EmailFrom = "xxxxx"

                [string[]]$EmailTo = "xxx"
                [string[]]$EmailBody = ("the Virtual Machine {0}" -f $VM.Name)
                $Subject = $VM.NAME + " notification of scheduled start"

                $Body = "Dear User<br><br>We'd like to let you know that $EmailBody has successfully started.
                <br>This could either be due to maintenance or a scheduled startup. If you were expecting this notification, please disregard this email.
                <br><br>If you need any further assistance, please contact the system administrator on globalitsupport@indomtrading.com<br><br>Yours Sincerely<br><br>The Technical Design Team<br>technical@indomtrading.com<br><br>"

                Send-MailMessage -smtpServer $SMTPServer -Credential $credential -Usessl -Port 587 -from $EmailFrom -to $EmailTo -subject $Subject -Body $Body -BodyAsHtml
                Write-Output "Email sent succesfully."
                
            }
            else
            {
                #$Body = "Dear User <br><br>The Virtual Machine $EmailBody failed to start. Please login to your Azure Account and check your diagnostics portal for the error message $ErrorMessage.
                #<br><br>
                #Yours Sincerely
                #<br>
                #The Technical Administraion Team
                #<br><br>
                #technical@indomtrading.com"
                # The VM failed to start, so send notice
                Write-Output ($VM.Name + " has failed to start. Please go back and check the Powersheel code for diagnostics.")
                
            }
   
 
}

有人对发生的事情有任何线索吗?

Does anyone have any resemblance of a clue as to what is going on?

谢谢

托德

推荐答案

托德(Hi Todd),

Hi Todd,

我不确定您在这里期望哪种答案.

I'm not sure which kind of answer you expect here.

在对您的代码有疑问的情况下:逗号,"参数的声明之间缺少.

In case of questions to your code: A comma "," is missing between the declaration of the parameters.

此致

Stefan


这篇关于在表达式或语句中获取意外标记')'.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆