powershell - 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] 任何人都可以帮助解决这个问题。
解决方案
推荐阅读
- git - 通过 SSH 从远程服务器推送 git commit:权限被拒绝(公钥)。致命:无法从远程存储库中读取
- android - 将横幅广告放在带有片段Android的父级底部
- go - golang grpc transport.newBufWriter 和 bufio.NewReaderSize 不释放内存
- c++ - 地毯驱动程序产生错误
- autocomplete - 如何清除 SublimeText Jedi-autocomplete 填充的方法调用参数/参数?
- python - 如何删除元组列表中重复的交换元组?
- r - 根据列值和主键删除列的R函数?
- typescript - 通过选择选项过滤数组
- python-3.x - 已安装 gfortran-9,但出现“未找到 Fortran 编译器”错误(Ubuntu Server 18.04)
- d3.js - 使用 D3 版本 4 的具有折叠框的 D3 树