2

当我调用这个脚本时给我一个例外

字符串缺少终止符:"

 using (var powershell = PowerShell.Create())
                {
                    powershell.Runspace = myRunSpace;
                    Collection<ErrorRecord> errors = null;
                    Collection<PSObject> result = null;

                    string psScript = @"
                                            $ApplicationID=" + applicationID +
                                      "\n" +
                                      "$ApplicationPort" + port + "\n" +
                                      "$Registrar=" + registrar + "\n" +
                                      "$NewPoolIdentity=" + poolIdentity + "\n" +
                                      "$ScriptName =" + scriptName + "\n" +
                                      "$SiteName= (get-cspool -Identity $Registrar).Site" + "\n" +
                                      "$Site= (get-cssite -Identity $SiteName).SiteId" + "\n" +
                                      "$ComputerFqdn =[System.Net.Dns]::GetHostByName(($env:computerName)).HostName" +
                                      "\n" +
                                      "$com=New-Object -ComObject CertificateAuthority.Config" + "\n" +
                                      "$CertificationAuthority = $com.GetConfig(0)" + "\n" +
                                      "$CertificateFriendlyName =$NewPoolIdentity +\" Pool" + "\n" +
                                      "$ApplicationFullID =$ApplicationID+ $ApplicationPort" + "\n" +
                                      "$DefaultSipDomain = (Get-CsSipDomain | where-object { $_.IsDefault -eq $true}).Name" +
                                      "\n" +
                                      "$ApplicationSipAddress = \"sip:\" + $ApplicationFullID + \"@\" + $DefaultSipDomain" +
                                      "\n" +
                                      "New-CsTrustedApplicationPool -Identity $NewPoolIdentity -Registrar $Registrar -RequiresReplication $false -Site $Site -ComputerFqdn $ComputerFqdn" +
                                      "\n" +
                                      "$MyTrustedApplications=New-CSTrustedApplication –ApplicationId $ApplicationFullID -TrustedApplicationPoolFqdn $NewPoolIdentity -Port $ApplicationPort" +
                                      "\n" +
                                      "Enable-CsTopology" + "\n" +
                                      "$Cert=Request-CsCertificate -New -Type default -FriendlyName $CertificateFriendlyName -CA $CertificationAuthority -ComputerFQDN $ComputerFqdn" +
                                      "\n" +
                                      "Set-CsCertificate -Type Default -Thumbprint $Cert.Thumbprint" + "\n" +
                                      "$ApplicationIdentity =  \"Registrar:\"+ $Registrar + \"/\" + $ApplicationFullID " +
                                      "\n" +
                                      "$ApplicationURI= \"http://www.sdsdsds.com/Apps/\" + $ApplicationID" + "\n" +
                                      "New-CsServerApplication -Identity $ApplicationIdentity -ScriptName $ScriptName -Uri $ApplicationURI -Priority 6 -Critical $False -Enabled $True" +
                                      "\n" +
                                      "New-CsTrustedApplicationEndpoint -ApplicationId $ApplicationFullID -TrustedApplicationPoolFqdn $NewPoolIdentity -SipAddress $ApplicationSipAddress" +
                                      "\n" +
                                      " $FinalResult = new-object PSObject;" +
                                      "\n" +
                                      "$FinalResult | add-member NoteProperty -Name Gruu $MyTrustedApplications.ComputerGruuS[0].Gruu;" +
                                      "\n" +
                                      "$FinalResult | add-member NoteProperty -Name LocalMachineFqdn $MyTrustedApplications.ComputerGruuS[0].Fqdn; " +
                                      "\n" +
                                      "$FinalResult | add-member NoteProperty -Name Port $MyTrustedApplications.Port; " +
                                      "\n" +
                                      "$FinalResult | add-member NoteProperty -Name ApplicationPoolFqdn $MyTrustedApplications.TrustedApplicationPoolFqdn; " +
                                      "\n" +
                                      "$FinalResult | add-member NoteProperty -Name Registrar $TrustedApplicationPool.Registrar; " +
                                      "\n" +
                                      "$FinalResult | add-member NoteProperty -Name CertificateFriendlyName $CertificateFriendlyName" +
                                      "\n" +
                                      "$FinalResult | add-member NoteProperty -Name ApplicationSipAddress $ApplicationSipAddress" +
                                      "\n" + "$FinalResult";



                    powershell.Commands.AddScript(psScript);


                    try
                    {
                        result = powershell.Invoke();
                        errors = powershell.Streams.Error.ReadAll();
                        Console.Write(".");
                    }

任何人都可以帮助我找到错误

4

1 回答 1

2

您缺少 '=' 符号,靠近

"$ApplicationPort" + port + "\n"

并有未终止的报价

$CertificateFriendlyName =$NewPoolIdentity +" Pool

您需要对其进行编辑,以包括报价:

"$CertificateFriendlyName =$NewPoolIdentity +\" Pool" + "\"\n" +
于 2013-04-23T17:16:58.397 回答