Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
87 lines (72 sloc) 2.36 KB
<#
File : ExpandApplications.ps1
Author : Abid Nasim.
Date : February 18, 2017
Usage : .\ExpandApplications.ps1 -msiDir <msidir> [-server <server>] [-database <database>] [-expandDir <expandDir>]
Example: .\ExpandApplications.ps1 -msiDir C:\msi # expands MSI files in C:\MSI folder
© Generalsoft Corporation, 2017.
Distributed "as is" with no expressed or implied warranty nor direct or contingent liability whatsoever, even if defects exist, known or unknown
Under MIT License. (see LICENSE in the top folder).
#>
Param(
[parameter(Mandatory=$true)][string]$msiDir,
[string]$expandDir = $env:TEMP
)
$errorActionPreference="stop"
Write-Host "Starting ...." -ForegroundColor Gray
if (!(Test-Path -path $msiDir))
{
Write-Host "Unable to locate $msiDir. " -ForegroundColor Yellow -BackgroundColor Red
exit
}
if (!(Test-Path -path $expandDir))
{
New-Item -path $expandDir -ItemType Directory
}
$files = Get-ChildItem -path "$msiDir\*.msi"
ForEach ($file in $files)
{
$path = "$expandDir\" + $file.Directory.Parent + "\" + $file.Directory.Name
if (!(Test-Path -Path $path))
{
New-Item -path $path -type directory
}
$path = "$expandDir\" + $file.Directory.Parent + "\" + $file.Directory.Name + "\" + $file.BaseName
if (Test-Path -Path $path)
{
Remove-Item -Path $path -Recurse -Force
}
if (!(Test-Path -Path $path))
{
New-Item -path $path -type directory
}
if (Test-Path -Path $path)
{
msiexec.exe /a "$file" /qb TARGETDIR="$path" | Out-Null
$cabs = Get-ChildItem -path "$path\*.cab" -Recurse
ForEach ($cab in $cabs)
{
expand -r $cab $path | Out-Null
}
$dlls = Get-ChildItem -path "$path\*.dll" -Recurse
ForEach ($dll in $dlls)
{
Move-Item $dll.FullName $path
}
ForEach ($item in Get-ChildItem -path $path -Recurse -Directory )
{
if (Test-Path $item.FullName)
{
Remove-item $item.FullName -Recurse -Force
}
}
ForEach ($item in Get-ChildItem -path $path -Recurse -File -Exclude "*.dll")
{
if (Test-Path $item.FullName)
{
Remove-item $item.FullName -Force
}
}
}
}
Write-Host "Done ...." -ForegroundColor Gray