This shows you the differences between two versions of the page.
userspace:msi_to_opsi [2013/07/30 07:02] qx23 |
userspace:msi_to_opsi [2021/08/23 08:37] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== MSI to OPSI ====== | ||
- | Tested on: Win7 64-bit | ||
- | Requieres: Powershell 2.0, MSI Module for Powershell | ||
- | |||
- | Download MSI Module for Powershell: http:// | ||
- | |||
- | |||
- | Dieses Powershellscript extrahiert informationen aus MSI Paketen und erstellt automatisiert anhand eines Templates fertige Opsiskripte inkl. control-Datei und der passenden Verzeichnisstruktur um die fertigen Daten auf den Opsiserver kopieren zu können. | ||
- | |||
- | ===== msi_to_opsi.ps1 ===== | ||
- | |||
- | < | ||
- | # Version: 0.1 | ||
- | # Date: 30.7.2013 | ||
- | # Author: Chris | ||
- | # Description: | ||
- | # How to use: MSI Files in poolfoldername will be processed by msi powershell module. Place MSI files in folder pool, run script, retrieve ready to use Opsi scripts from folder OUTPUT | ||
- | |||
- | $testmodulemsi = Get-Module -ListAvailable | Where-Object { $_.name -eq " | ||
- | if (($testmodulemsi)) | ||
- | { | ||
- | Import-Module -Name MSI -ErrorAction SilentlyContinue | ||
- | Write-Host " | ||
- | } | ||
- | else { | ||
- | Write-Host `n" | ||
- | Write-Host "THIS IS A FATAL ERROR. EXITING NOW." | ||
- | exit | ||
- | } | ||
- | |||
- | $DateTime = (Get-Date -Format s) -Replace " | ||
- | |||
- | ## Specify some global settings | ||
- | |||
- | $BaseFolder = " | ||
- | |||
- | # Poolfoldername is the location with the basefolder where the installers and theire procducte images are located. | ||
- | $PoolFolderName = " | ||
- | $InputFolder = $BaseFolder + " | ||
- | |||
- | # OPSI Package Parameter | ||
- | $DefaultValueMinimumspace = "1000 MB" | ||
- | $priority = " | ||
- | $packageversion = " | ||
- | |||
- | # Set Log Folder | ||
- | $LogFolder = " | ||
- | If(!(Test-Path " | ||
- | $log = $LogFolder + " | ||
- | |||
- | # MSI Parameter | ||
- | $installparameter = "/gb-! REBOOT=REALLYSUPPRES" | ||
- | $uninstallparameter = "/gb-! REBOOT=REALLYSUPPRES" | ||
- | |||
- | |||
- | # Move finishe packages to Opsi server. Not implementet (yet) | ||
- | $CopyToOpsiServer = $false | ||
- | $OpsiServerName = " | ||
- | $OpsiUserName = " | ||
- | $OpsiPasswordName = " | ||
- | $CreatedLinuxShellScript = $false | ||
- | |||
- | foreach ($msifile in Get-ChildItem .\Pool -Filter *.msi -name) { | ||
- | |||
- | $fullmsifile = $InputFolder + $msifile | ||
- | $productName = get-msitable $fullmsifile -table Property | where-object { $_.Property -eq " | ||
- | $productNameFlat = ($productName) -Replace " ", " | ||
- | $description = " | ||
- | |||
- | $progamversion = get-msitable $fullmsifile -table Property | where-object { $_.Property -eq " | ||
- | $msiid = get-msitable $fullmsifile -table Property | where-object { $_.Property -eq " | ||
- | |||
- | $uninstallprogramm = $msifile | ||
- | $uninstallprogramm = $msifile | ||
- | $installexec = $msifile | ||
- | |||
- | write-host " | ||
- | |||
- | $packagename = $productName.ToLower() | ||
- | $OutputPackageFolder = $BaseFolder + " | ||
- | $InstallerExecutable = $fullmsifile | ||
- | $OutputPackageFolderClientData = $OutputPackageFolder + ' | ||
- | |||
- | # Create packagefolder structur | ||
- | " | ||
- | |||
- | If(!(Test-Path " | ||
- | { | ||
- | New-Item -ItemType Directory -Path " | ||
- | " | ||
- | } | ||
- | Else | ||
- | { | ||
- | " | ||
- | } | ||
- | If(!(Test-Path " | ||
- | { | ||
- | New-Item -ItemType Directory -Path " | ||
- | " | ||
- | } | ||
- | Else | ||
- | { | ||
- | " | ||
- | } | ||
- | |||
- | If(!(Test-Path " | ||
- | { | ||
- | New-Item -ItemType Directory -Path " | ||
- | " | ||
- | } | ||
- | Else | ||
- | { | ||
- | " | ||
- | } | ||
- | |||
- | |||
- | $minimumspace = $DefaultValueMinimumspace | ||
- | |||
- | # Create setup.ins | ||
- | $original_file_setup_ins = $BaseFolder + ' | ||
- | $destination_file_setup_ins = $OutputPackageFolder + ' | ||
- | |||
- | (Get-Content $original_file_setup_ins) | Foreach-Object { | ||
- | $_ -replace ' | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | } | Set-Content $destination_file_setup_ins | ||
- | |||
- | # Create uninstall.ins | ||
- | |||
- | $original_file_uninstall_ins = $BaseFolder + ' | ||
- | $destination_file_uninstall_ins = $OutputPackageFolder + ' | ||
- | |||
- | (Get-Content $original_file_uninstall_ins) | Foreach-Object { | ||
- | $_ -replace ' | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | } | Set-Content $destination_file_uninstall_ins | ||
- | |||
- | # Create delsub.ins | ||
- | |||
- | $original_file_delsub_ins = $BaseFolder + ' | ||
- | $destination_file_delsub_ins = $OutputPackageFolder + ' | ||
- | |||
- | (Get-Content $original_file_delsub_ins) | Foreach-Object { | ||
- | $_ -replace ' | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | } | Set-Content $destination_file_delsub_ins | ||
- | |||
- | |||
- | # Create OPSI Controlfile | ||
- | $original_file_opsi_control = $BaseFolder + " | ||
- | $destination_file_opsi_control = $OutputPackageFolder + " | ||
- | |||
- | (Get-Content $original_file_opsi_control) | Foreach-Object { | ||
- | $_ -replace " | ||
- | -replace ' | ||
- | -replace ' | ||
- | -replace ' | ||
- | -replace ' | ||
- | -replace ' | ||
- | } | Set-Content $destination_file_opsi_control | ||
- | |||
- | # Copy executable files und producticons | ||
- | |||
- | If(!(Test-Path $InstallerExecutable)) | ||
- | { | ||
- | Write-Host " | ||
- | " | ||
- | } | ||
- | Else | ||
- | { | ||
- | Copy-Item -Path $InstallerExecutable -Destination $OutputPackageFolderClientData | ||
- | } | ||
- | |||
- | } | ||
- | |||
- | </ | ||
- | |||
- | ===== setup.ins ===== | ||
- | |||
- | <code winst> | ||
- | [Actions] | ||
- | requiredWinstVersion >= " | ||
- | |||
- | DefVar $MsiId$ | ||
- | DefVar $UninstallProgram$ | ||
- | DefVar $LogDir$ | ||
- | DefVar $ProductId$ | ||
- | DefVar $MinimumSpace$ | ||
- | DefVar $InstallDir$ | ||
- | DefVar $InstallProg$ | ||
- | DefVar $ExitCode$ | ||
- | DefVar $UninstCMD$ | ||
- | DefVar $InstCMD$ | ||
- | DefVar $DisplayName$ | ||
- | DefVar $ProductName$ | ||
- | |||
- | Set $LogDir$ = " | ||
- | |||
- | ; ---------------------------------------------------------------- | ||
- | ; - Please edit the following values | ||
- | ; ---------------------------------------------------------------- | ||
- | ; | ||
- | ; therefore please: only lower letters, no umlauts, | ||
- | ; no white space use ' | ||
- | Set $ProductId$ | ||
- | Set $ProductName$ | ||
- | Set $MinimumSpace$ | ||
- | |||
- | Set $InstallDir$ | ||
- | Set $InstallProg$ | ||
- | Set $UninstallProgram$ = " | ||
- | Set $UninstCMD$ = " PSVAR_UNINSTALLPARAMETER" | ||
- | Set $InstCMD$ = " PSVAR_INSTALLPARAMETER" | ||
- | Set $MsiId$ = " | ||
- | |||
- | ; ---------------------------------------------------------------- | ||
- | |||
- | if not(HasMinimumSpace (" | ||
- | LogError "Not enough space on %SystemDrive%, | ||
- | isFatalError | ||
- | ; Stop process and set installation status to failed | ||
- | else | ||
- | |||
- | if FileExists(" | ||
- | comment "Start uninstall sub section" | ||
- | Sub " | ||
- | endif | ||
- | |||
- | Message " | ||
- | Winbatch_install | ||
- | sub %scriptpath%\check_exitcode\check_msi-exitcode.ins | ||
- | endif | ||
- | |||
- | [Winbatch_install] | ||
- | msiexec /i $InstallProg$ $InstCMD$ | ||
- | </ | ||
- | |||
- | === uninstall.ins === | ||
- | |||
- | <code winst> | ||
- | [Actions] | ||
- | requiredWinstVersion >= " | ||
- | |||
- | DefVar $MsiId$ | ||
- | DefVar $UninstallProgram$ | ||
- | DefVar $LogDir$ | ||
- | DefVar $ProductId$ | ||
- | DefVar $MinimumSpace$ | ||
- | DefVar $InstallDir$ | ||
- | DefVar $InstallProg$ | ||
- | DefVar $ExitCode$ | ||
- | DefVar $UninstCMD$ | ||
- | DefVar $InstCMD$ | ||
- | DefVar $DisplayName$ | ||
- | DefVar $ProductName$ | ||
- | |||
- | Set $LogDir$ = " | ||
- | |||
- | ; ---------------------------------------------------------------- | ||
- | ; - Please edit the following values | ||
- | ; ---------------------------------------------------------------- | ||
- | ; | ||
- | ; therefore please: only lower letters, no umlauts, | ||
- | ; no white space use ' | ||
- | Set $ProductId$ | ||
- | Set $ProductName$ | ||
- | Set $MinimumSpace$ | ||
- | |||
- | Set $InstallDir$ | ||
- | Set $InstallProg$ | ||
- | Set $UninstallProgram$ = " | ||
- | Set $UninstCMD$ = " PSVAR_UNINSTALLPARAMETER" | ||
- | Set $InstCMD$ = " PSVAR_INSTALLPARAMETER" | ||
- | Set $MsiId$ = " | ||
- | |||
- | |||
- | ; ---------------------------------------------------------------- | ||
- | |||
- | Message " | ||
- | |||
- | if FileExists(" | ||
- | comment "Start uninstall sub section" | ||
- | Sub " | ||
- | else | ||
- | Log " | ||
- | Message " | ||
- | endif | ||
- | </ | ||
- | |||
- | ===== delsub.ins ===== | ||
- | |||
- | <code winst> | ||
- | Set $DisplayName$ = GetRegistrystringvalue32(" | ||
- | if not ($DisplayName$ = "" | ||
- | comment "MSI ID found in Registry, starting uninstall" | ||
- | Message " | ||
- | set $UninstallProgram$ = " | ||
- | Winbatch_Uninstall | ||
- | sub %scriptpath%\check_exitcode\check_msi-exitcode.ins | ||
- | else | ||
- | comment " | ||
- | endif | ||
- | |||
- | Set $DisplayName$ = GetRegistrystringvalue64(" | ||
- | if not ($DisplayName$ = "" | ||
- | comment "MSI ID found in Registry, starting uninstall" | ||
- | Message " | ||
- | set $UninstallProgram$ = " | ||
- | Winbatch_Uninstall | ||
- | sub %scriptpath%\check_exitcode\check_msi-exitcode.ins | ||
- | else | ||
- | comment " | ||
- | endif | ||
- | |||
- | [Winbatch_uninstall] | ||
- | " | ||
- | </ | ||
- | |||
- | ===== control ===== | ||
- | |||
- | <code winst> | ||
- | [Package] | ||
- | version: PSVAR_PACKAGEVERSION | ||
- | depends: | ||
- | incremental: | ||
- | |||
- | [Product] | ||
- | type: localboot | ||
- | id: PSVAR_PACKAGENAME | ||
- | name: PSVAR_NAME | ||
- | description: | ||
- | advice: | ||
- | version: PSVAR_PROGRAMMVERSION | ||
- | priority: PSVAR_PRIORITY | ||
- | licenseRequired: | ||
- | productClasses: | ||
- | setupScript: | ||
- | uninstallScript: | ||
- | updateScript: | ||
- | alwaysScript: | ||
- | onceScript: | ||
- | customScript: | ||
- | userLoginScript: | ||
- | </ | ||
- | |||
- | ===== check_msi-exitcode.ins ===== | ||
- | <code winst> | ||
- | ;Den ExitCode des Installers abfragen | ||
- | set $ExitCode$ = getLastExitCode | ||
- | |||
- | ;Loglevel anpassen | ||
- | setLogLevel = 4 | ||
- | | ||
- | ;Den ExitCode auswerten | ||
- | |||
- | if ($ExitCode$ = " | ||
- | | ||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | comment " | ||
- | setLogLevel = 4 | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | comment " | ||
- | setLogLevel = 4 | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | comment " | ||
- | setLogLevel = 4 | ||
- | endif | ||
- | |||
- | |||
- | |||
- | else | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | |||
- | |||
- | if ($ExitCode$ = " | ||
- | setLogLevel = 5 | ||
- | logError " | ||
- | isFatalError | ||
- | endif | ||
- | |||
- | endif | ||
- | |||
- | ;Loglevel anpassen | ||
- | setLogLevel = 6 | ||
- | </ |