This is an example on how to create and call a Powerpack script from a CapaInstaller script (.cis)
insert code in a .cis script to call a powershell install script
If bStatus Then bStatus = File_FindFile("pwsh.exe", gsProgramfiles & "\PowerShell", True) If bStatus and isArray(gaValue) Then sPwshPath=gaValue(0) If bStatus and sPwshPath<>"" Then bStatus = File_GetVersion(sPwshPath, True) sPwshVersion=gsValue call Job_WriteLog("***********","Powershell installed: " & sPwshPath,true,true) call Job_WriteLog("***********","Powershell version installed: " & sPwshVersion,true,true) Else bStatus=Job_ErrorHandling("***********","Powershell (Core) must be installed.", 0) End if PSArgs="-Packageroot " & """" & gsPackageroot & """" PSArgs=PSArgs & " -AppName " & """" & sAppName & """" PSArgs=PSArgs & " -DllPath " & """" & gsWorkstationPath & "Lib\CapaOne.ScriptingLibrary.dll" & """" PSArgs=PSArgs & " -AppRelease " & """" & sPackageVersion & """" PSArgs=PSArgs & " -LogFile " & """" & gsLogdir & sAppName & "\" & sPackageVersion & "\" & sAppName & ".ps_Install.log" & """" PSArgs=PSArgs & " -TempFolder " & """" & gsTempdir & """" If bStatus Then bStatus=shell_execute(sPwshPath,"-ExecutionPolicy bypass -file " & """" & gsPackageroot & "\kit\Install.ps1" & """" & " " & PSArgs,True,0,False) If bStatus And giErrorlevel=3326 Then bStatus=CMS_JobRetryLater("Package will retry later.") If bStatus And giErrorlevel=3330 Then giErrorlevel=0 If bStatus And giErrorlevel=3010 Then giErrorlevel=0 If bStatus Then bStatus=cbool(giErrorlevel=0)
powershell script example (pslib.psm1 is a powerpack ps module and is used to load scripting library dll and handles exit codes)
[CmdletBinding()] Param( [Parameter(Mandatory=$true)] [string]$Packageroot, [Parameter(Mandatory=$true)] [string]$AppName, [Parameter(Mandatory=$true)] [string]$AppRelease, [Parameter(Mandatory=$true)] [string]$LogFile, [Parameter(Mandatory=$true)] [string]$TempFolder, [Parameter(Mandatory=$true)] [string]$DllPath, [Parameter(Mandatory=$false)] [Object]$InputObject=$null ) try { #global variables [string]$global:ProductVersion = "1.65.2" [string]$global:LogFolder = Split-Path $LogFile -Parent [string]$global:InstallFile = "$Packageroot\kit\VSCodeSetup-x64-$global:ProductVersion.exe" [string]$global:InstallArgs = "/VERYSILENT /NORESTART /LANG=en /MERGETASKS=!runcode,addcontextmenufiles,addtopath /LOG=`"$(Join-Path $global:LogFolder $AppName).app.log`"" ############################################## #load core PS lib - don't mess with this! if ($InputObject){$pgkit=""}else{$pgkit="kit"} Import-Module (Join-Path $Packageroot $pgkit "PSlib.psm1") -ErrorAction Stop #load Library dll $cs=Add-PSDll ############################################## $cs.Job_Start("WS",$AppName,$AppRelease,$LogFile,"INSTALL") $cs.Job_WriteLog("[Init]: Starting package: '" + $AppName + "' Release: '" + $AppRelease + "'") if(!$cs.Sys_IsMinimumRequiredDiskspaceAvailable('c:',300)){Exit-PSScript 3333} if ($global:DownloadPackage -and $InputObject){Start-PSDownloadPackage} $retvalue=$cs.Shell_Execute($global:InstallFile,$global:InstallArgs,$true,0,$true) if ($retvalue -ne 0){Exit-PSScript $retvalue} $cs.Job_WriteLog("Install:","$AppName completed with status: $retvalue") Exit-PSScript $Error } catch { $cs.Job_WriteLog("*****************","Something bad happend: " + $_.Exception.Message) Exit-PSScript $_.Exception.HResult }
ScriptingLibrary dll.
Skal placeres i gsWorkstationpath & "Lib\CapaOne.ScriptingLibrary.dll"
Seneste version er 0.2.0.0