powershell - msiexec 没有对提供的路径进行精确处理
问题描述
这个问题在这里已经讨论过了,但没有给出明确的答案,所以再次提出。
我正在尝试提取 .msi 文件的内容,如下所示:
function script:Export-MsiContents
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true, Position = 0)]
[ValidateNotNullOrEmpty()]
[ValidateScript({Test-Path $_})]
[ValidateScript({$_.EndsWith(".msi")})]
[String] $MsiPath,
[Parameter(Mandatory=$false, Position = 1)]
[String] $TargetDirectory
)
if(-not($TargetDirectory))
{
$currentDir = [System.IO.Path]::GetDirectoryName($MsiPath)
Write-Warning "A target directory is not specified. The contents of the MSI will be extracted to the location, $currentDir\Temp"
$TargetDirectory = Join-Path $currentDir "Temp"
}
$MsiPath = Resolve-Path $MsiPath
Write-Verbose "Extracting the contents of $MsiPath to $TargetDirectory"
Start-Process "MSIEXEC" -ArgumentList "/a $MsiPath /qn TARGETDIR=$TargetDirectory" -Wait -NoNewWindow
}
并且没有提取 .msi 文件。
解决方案
1.转义:PowerShell中的转义字符是重音: `( ASCII:96, Unicode:U + 0060 - 我认为)。重音在编程中的使用。尝试如下逃脱:
Start-Process "MSIEXEC" -ArgumentList "/a `"C:\my setup.msi`" /qn TARGETDIR=`"C:\Extract here`"" -Wait -NoNewWindow
2.“停止解析”:PSv3+
提供--%
,停止解析符号(更多来自ss64.com)。它将命令行的其余部分按原样传递给外部实用程序,以保存 %...% 样式环境变量的潜在扩展:
# Everything after --% is passed as-is.
msiexec --% /a "C:\my setup.msi" /qn TARGETDIR="C:\Extract here"
我不是 Powershell 专家。以上基于:
其他链接:
推荐阅读
- javascript - 在列表中查找重复对象并添加参数
- performance - Applescript for Illustrator:如何制作多个项目?
- c# - 使用 .NET Core 3.1 的命令行 arg 指定 Kestrel 端口
- javascript - 如何将json项目推送到数组?
- flutter - 在 Flutter 中使用集合包的问题
- python-3.x - 循环访问先前元素的 pandas DataFrame
- python-3.x - 无法在 ApplicationLoadBalancedFargateService 中为容器设置环境变量
- python - 如何实现检查系统是否一致的功能?
- exception - F# TaskBuilder:如何在不返回虚拟值的情况下引发异常以符合编译器约束?
- python - Python 获取请求所有页面