The issue has already been discussed here, but did not end up with any clear answer, so it is raised again.
I am trying to extract the contents of an .msi file as follows:
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
}
Once called I get the window pop up . Please take a look at the attached screenshot
And there is no extraction of the .msi file.
1. Escaping: The escape character in PowerShell is the grave-accent: ` (ASCII: 96, Unicode: U+0060 - I think). Grave accent use in programming. Try to escape as follows:
Start-Process "MSIEXEC" -ArgumentList "/a `"C:\my setup.msi`" /qn TARGETDIR=`"C:\Extract here`"" -Wait -NoNewWindow
2. "Stop Parsing": PSv3+
offers --%
, the stop-parsing symbol (more from ss64.com). It passes the rest of the command line as-is to the external utility, save for potential expansion of %...%-style environment variables:
# Everything after --% is passed as-is.
msiexec --% /a "C:\my setup.msi" /qn TARGETDIR="C:\Extract here"
I am not a Powershell expert. The above based on:
Other Links: