Skip to content

Instantly share code, notes, and snippets.

@edwinheij
Last active June 5, 2016 20:26
Show Gist options
  • Save edwinheij/e22bcea59ff204f06cdd427f8b211c29 to your computer and use it in GitHub Desktop.
Save edwinheij/e22bcea59ff204f06cdd427f8b211c29 to your computer and use it in GitHub Desktop.
Versie controle op 2 bestanden en eventueel updaten via setup als versies verschillen
. ./ShouldBeUpToDate.ps1
$pathExecutible = "C:\Program Files\Git\git-cmd.exe"
$pathSetupfile = "C:\Users\<username>\Downloads\Git-2.8.3-64-bit.exe"
ShouldBeUpToDate -pathExecutible $pathExecutible -pathSetupfile $pathSetupfile
function ShouldBeUpToDate {
[cmdletbinding()]
param(
[parameter(Mandatory=$true)] [String] $pathExecutible,
[parameter(Mandatory=$true)] [String] $pathSetupfile
)
try {
$versionExecutible = getVersionFromFile -filepath $pathExecutible
$versionSetup = getVersionFromFile -filepath $pathSetupfile
$difference = Compare-Object -ReferenceObject $versionExecutible -DifferenceObject $versionSetup -Property ProductBuildPart, ProductMajorPart, ProductMinorPart #, ProductPrivatePart
if ($difference.count -ne 0) {
updateSoftwarePackage -filepath $pathSetupfile
} else {
Write-Host Geen update nodig ...
}
} catch {
Write-Error $error[0].Exception.Message
}
}
function getVersionFromFile {
param(
[parameter(Mandatory=$true)] [String] $filepath
)
return [System.Diagnostics.FileVersionInfo]::GetVersionInfo($filepath)
}
function updateSoftwarePackage {
param(
[parameter(Mandatory=$true)] [String] $filepath
)
Write-Host Updating $filepath ....
if ((Get-ChildItem -Path $filepath).Extension -eq ".exe") {
install-EXE -filepath $filepath
} elseif ((Get-ChildItem -Path $filepath).Extension -eq ".msi") {
install-MSI -filepath $filepath
}
}
function install-MSI {
param(
[parameter(Mandatory=$true)] [String] $filepath
)
$product = [WMICLASS]"\\.\ROOT\CIMV2:win32_Product"
$installedProduct = $product.Install($filepath,"ADDLOCAL=ALL", $true)
if ($installedProduct.returnValue -ne 0) {
Write-Host "Installatie niet gelukt voor '$filepath'" -ForegroundColor Red
} else {
Write-Host "Installatie gelukt voor '$filepath' met exitcode $($installedProduct.returnValue)" -ForegroundColor Green
}
}
function install-EXE {
param(
[parameter(Mandatory=$true)] [String] $filepath
)
$commandlineInstallation = "cmd.exe /c `"$filepath /SP- /VERYSILENT /LOG /NORESTART /CLOSEAPPLICATIONS /RESTARTAPPLICATIONS`" /qn"
([WMICLASS]"\\.\ROOT\CIMV2:win32_process").Create($commandlineInstallation)
Write-Host "Installatie gelukt voor '$filepath'" -ForegroundColor Green
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment