首页 > 解决方案 > Powershell错误字符串缺少终止符:'

问题描述

我有以下脚本并在 Windows 2012 R2 服务器上运行。此脚本将在 IIS 中创建 AppPool 和站点。

Import-Module "WebAdministration"

if(Test-Path IIS:\AppPools\MgmtSite){ } else { New-Item IIS:\AppPools\MgmtSite -force  }

if(Test-Path 'iis:\Sites\Mgmt Site'){ New-WebBinding -name 'Mgmt Site' -Protocol http -IPAddress '*' -Port 80 } else { New-Item 'iis:\Sites\Mgmt Site' -bindings @{protocol='http';bindingInformation='*:80:'} -physicalPath 'C:\Program Files\AP\MgmtServices' -force }

Set-ItemProperty 'iis:\Sites\Mgmt Site' -name applicationPool -value MgmtSite

$newId = (Get-ChildItem IIS:\Sites | where{$_.Name -eq 'Mgmt Site'}).Id

Write-Host -Object "Mgmt Site ID is: $newId " 

New-WebBinding -name 'Mgmt Site' -Protocol https -IPAddress '*' -Port 443 -SslFlags 0

Start-WebSite 'Mgmt Site' 

 if( !((Get-WebConfiguration //staticcontent).collection | ? {$_.fileextension -eq '.woff'}) ) {  add-webconfigurationproperty //staticContent -name collection -value @{fileExtension='.woff'; mimeType='application/font-woff'}   } 

 if( !((Get-WebConfiguration //staticcontent).collection | ? {$_.fileextension -eq '.woff2'}) ) {  add-webconfigurationproperty //staticContent -name collection -value @{fileExtension='.woff2'; mimeType='application/font-woff2'}   } 

 if( !((Get-WebConfiguration //staticcontent).collection | ? {$_.fileextension -eq '.webm'}) ) {  add-webconfigurationproperty //staticContent -name collection -value @{fileExtension='.webm'; mimeType='video/webm'}   }

在服务器上执行时出现以下错误,

> At C:\Users\*****\AppData\Local\Temp\2\nsz8E60.tmp\temp_script.ps1:11 char:213
+ ... ype='video/webm'}   }
+                    ~~~~~~
The string is missing the terminator: '.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

但是相同的脚本正在其他服务器上运行。[服务器上的 Poweshell 版本是 4.0] 任何人都可以帮助解决这个问题。

标签: powershellwindows-server-2012-r2

解决方案


推荐阅读