MSI Sourcelist and PSADT

//MSI Sourcelist and PSADT
MSI Sourcelist and PSADT 2016-09-18T11:00:40+00:00

The Toolkit Forums Deployment Scripts MSI Sourcelist and PSADT

  • Author
    Posts
  • Francois
    Participant
    Post count: 101
    #1639 |

    Hi,

    With much help, I create this script to add sourcelist’s path to MSI. I hope it might help.

    <code>Function AddSourceList {
        &lt;#
        .SYNOPSIS
        Ajoute un chemin au sourcelist d&#039;un MSI
        .DESCRIPTION
        Ajoute un chemin au sourcelist d&#039;un MSI
        .Parameter
        Str_MSIPathAndFile
        Donner un chemin complet d&#039;un MSI incluant le nom du fichier. Le MSI doit se trouver dans le répertoire.
        .EXAMPLE
        AddSourcelist MSI
         #&gt;
        [CmdletBinding()]
        param(
            [Parameter(Mandatory=$true)]
            [string]$Str_MSIPathAndFile
        )
        Begin {
    			## Get the name of this function and write header
    			[string]${CmdletName} = $PSCmdlet.MyInvocation.MyCommand.Name
    			Write-FunctionHeaderOrFooter -CmdletName ${CmdletName} -CmdletBoundParameters $PSBoundParameters -Header
    		}
        Process {
    
            Try {
    
                $MSIPath=split-path $Str_MSIPathAndFile
                $ProductCode= Get-MsiTableProperty -Path $Str_MSIPathAndFile
                #$productcode=&#039;{09AAAB09-6DBA-4DD9-9865-54597D3FBCA8}&#039;
                #$MSIPath=&#039;E:\Temp\Logiciels\Antidote 8\msi\druide&#039;
    
                $Com_WI = New-Object -ComObject WindowsInstaller.Installer
    
                $codeInvokeMethod = {
    	            $type = $this.gettype();
    	            $index = $args.count - 1;
    	            $methodargs = $args[1..$index]
    	            $type.invokeMember($args[0], [System.Reflection.BindingFlags]::InvokeMethod, $null, $this, $methodargs)
                }
                $Com_WI = $Com_WI | Add-Member -MemberType ScriptMethod -Value $codeInvokeMethod -Name InvokeMethod -PassThru
                            
                Try {
                    Write-log &quot;Ajout du Sourcelist $($MSIPath) au MSI $($Str_MSIPathAndFile) Product code $($productcode.productcode)&quot;
            	    $Com_WI.InvokeMethod(&#039;AddSource&#039;, &quot;$($productcode.productcode)&quot;, &#039;&#039;, &quot;$($MSIPath)&quot;)
                }
                Catch {
                    Write-Log -Message &quot;Failed to resolve registry path [$regKey]. </code>

    n$(Resolve-Error)” -Severity 3 -Source ${CmdletName}
    Continue
    }
    }
    catch {
    Write-Log -Message “Failed to resolve registry path [$regKey]. `n$(Resolve-Error)” -Severity 3 -Source ${CmdletName}
    Continue
    }

    }
    End {
    Write-FunctionHeaderOrFooter -CmdletName ${CmdletName} -Footer
    }

    }`

  • Francois
    Participant
    Post count: 101

    I hate the way how the code is manage on this site.

    Function AddSourceList {
    <#
    .SYNOPSIS
    Ajoute un chemin au sourcelist d’un MSI
    .DESCRIPTION
    Ajoute un chemin au sourcelist d’un MSI
    .Parameter
    Str_MSIPathAndFile
    Donner un chemin complet d’un MSI incluant le nom du fichier. Le MSI doit se trouver dans le rĂ©pertoire.
    .EXAMPLE
    AddSourcelist MSI
    #>
    [CmdletBinding()]
    param(
    [Parameter(Mandatory=$true)]
    [string]$Str_MSIPathAndFile
    )
    Begin {
    ## Get the name of this function and write header
    [string]${CmdletName} = $PSCmdlet.MyInvocation.MyCommand.Name
    Write-FunctionHeaderOrFooter -CmdletName ${CmdletName} -CmdletBoundParameters $PSBoundParameters -Header
    }
    Process {

    Try {

    $MSIPath=split-path $Str_MSIPathAndFile
    $ProductCode= Get-MsiTableProperty -Path $Str_MSIPathAndFile
    #$productcode='{09AAAB09-6DBA-4DD9-9865-54597D3FBCA8}’
    #$MSIPath=’E:\Temp\Logiciels\Antidote 8\msi\druide’

    $Com_WI = New-Object -ComObject WindowsInstaller.Installer

    $codeInvokeMethod = {
    $type = $this.gettype();
    $index = $args.count – 1;
    $methodargs = $args[1..$index]
    $type.invokeMember($args[0], [System.Reflection.BindingFlags]::InvokeMethod, $null, $this, $methodargs)
    }
    $Com_WI = $Com_WI | Add-Member -MemberType ScriptMethod -Value $codeInvokeMethod -Name InvokeMethod -PassThru

    Try {
    Write-log “Ajout du Sourcelist $($MSIPath) au MSI $($Str_MSIPathAndFile) Product code $($productcode.productcode)”
    $Com_WI.InvokeMethod(‘AddSource’, “$($productcode.productcode)”, ”, “$($MSIPath)”)
    }
    Catch {
    Write-Log -Message “Failed to resolve registry path [$regKey]. `n$(Resolve-Error)” -Severity 3 -Source ${CmdletName}
    Continue
    }
    }
    catch {
    Write-Log -Message “Failed to resolve registry path [$regKey]. `n$(Resolve-Error)” -Severity 3 -Source ${CmdletName}
    Continue
    }

    }
    End {
    Write-FunctionHeaderOrFooter -CmdletName ${CmdletName} -Footer
    }

    }

You must be logged in to reply to this topic.