PowerShell 缺少终止符 : "

标签 powershell powershell-2.0 powershell-3.0

我有以下脚本代码

#[string]$password = $( Read-Host "Input password, please" )
param (
    [string]$ReleaseFile = $(throw "-ReleaseFile is required"),
    [string]$Destination = $(throw "-Destination is required")
)
 
function unzipRelease($src, $dst)
{
    $shell = new-object -com shell.application
    $zip = $shell.NameSpace($src)
    foreach($item in $zip.items())
    {
        $shell.Namespace($dst).copyhere($item)
    }
}

#  .\deployrelease.ps1 -ReleaseFile ".\deploy.zip" -Destination "."

unzipRelease –Src '$ReleaseFile' -Dst '$Destination'

我使用以下命令运行脚本:.\deployrelease.ps1 -ReleaseFile ".\deploy.zip"-Destination "."

但我不断收到这个:

PS C:\Users\Administrator\Documents\Tools> .\deployrelease.ps1 -ReleaseFile ".\deploy.zip" -Destination
The string starting:
At C:\Users\Administrator\Documents\Tools\deployrelease.ps1:19 char:16
+ unzipRelease â? <<<< "Src '$ReleaseFile' -Dst '$Destination'
is missing the terminator: ".
At C:\Users\Administrator\Documents\Tools\deployrelease.ps1:19 char:55
+ unzipRelease â?"Src '$ReleaseFile' -Dst '$Destination' <<<<
    + CategoryInfo          : ParserError: (Src `'$ReleaseF...'$Destination`':String) [], ParseException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

我找不到修复程序,因为我没有发现任何问题。

有什么帮助吗?

最佳答案

仔细观察其中的两个破折号

unzipRelease –Src '$ReleaseFile' -Dst '$Destination'

第一个不是普通的破折号,而是一个短破折号(HTML 中的 )。将其替换为 Dst 之前找到的破折号。

关于PowerShell 缺少终止符 : ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20706869/

相关文章:

powershell - PowerShell的echo和CMD的echo的区别

powershell - Get-Website命令返回多个网站

powershell - 检查 AD 对象是否存在;如何避免丑陋的错误消息?

windows - 通过 PsExec 在远程计算机中执行批处理文件

c# - 我如何动态引用一个程序集来寻找另一个程序集?

regex - Powershell中的路径和字符串斩波

powershell - 无法捕获写警告生成的警告输出(到WarningVariable中)

PowerShell 问题 - 我必须键入 ./才能运行 bat 文件

regex - 在csv doc中使用powershell,需要迭代并插入字符

powershell - 用于在Active Directory中提取各种数据字段的Powershell脚本