Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch 1 #24

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 133 additions & 0 deletions Scripts/BatchConversion/ParallelPackaging.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<#

.SYNOPSIS
ParallelPackaging.ps1

.DESCRIPTION
Uses multiple local VMs in order to package in parallel all MSIs of a given folder
The syntax is:
ParallelPackaging.ps1 -VMNames <VMs name comma separated> -FolderContainingMSIs <folder path> -publisherName <publisher name>

.EXAMPLE
Use a full path to an .APPXBUNDLE file:
ParallelPackaging.ps1 -VMNames MSIXVM01,MSIXVM02 -FolderContainingMSIs C:\Temp\FolderWithMSIs\ -publisherName "Contoso Software (FOR LAB USE ONLY), O=Contoso Corporation, C=US"

.NOTES
All the VMs have to use the same login/password

.LINK
https://github.com/microsoft/MSIX-Toolkit/tree/master/Scripts/BatchConversion

#>[CmdletBinding()]
Param(
[parameter(Mandatory=$true, HelpMessage="Names of the local VMs to use to package MSIX (comma separated). All VMs must have the same login/password")]
[AllowEmptyString()]
[string[]]$VMNames,

[parameter(Mandatory=$true, HelpMessage="Folder containing all MSIs to package")]
[AllowEmptyString()]
[string]$FolderContainingMSIs,

[parameter(Mandatory=$true, HelpMessage="Exact name of the Publisher (will be used for the signing)")]
[AllowEmptyString()]
[string]$publisherName
)


# Include scripts from the MSI-Toolbox
. $PSScriptRoot\batch_convert.ps1
. $PSScriptRoot\sign_deploy_run.ps1




# Starting point
[System.Threading.Thread]::CurrentThread.CurrentCulture = [System.Globalization.CultureInfo]::CreateSpecificCulture("en-US")


if ($VMName -eq '') {
Write-Host "[Error] A VM name was not specified." -ForegroundColor Red
#Write-Host "Please use 'get-help .\MakeAPPXForWin10S.ps1' for more details"
exit
}


$credential = Get-Credential



Add-Type @'
public class CVMName
{
public string Name;
public System.Management.Automation.PSCredential Credential;
}
'@


$virtualMachines = @()

foreach ($o in $VMNames) {
$vm = New-Object CVMName
$vm.Name = $o
$vm.Credential = $credential
$virtualMachines += $vm
}


$remoteMachines = @(
#@{ ComputerName = "."; Credential = $credential }
)



Add-Type @'
public class Cparameter
{
public string InstallerPath;
public string PackageName;
public string PackageDisplayName;
public string PublisherName;
public string PublisherDisplayName;
public string PackageVersion;
}
'@


$conversionsParameters = @()

$root = $FolderContainingMSIs
get-childitem $root -recurse | Where-Object {$_.extension -eq ".msi"} | % {

$o = New-Object Cparameter
$o.InstallerPath = $_.FullName
$o.PackageName = $_.BaseName
$o.PackageDisplayName = $_.BaseName
$o.PublisherName = "CN=" + $publisherName;
$o.PublisherDisplayName = $publisherName;
$o.PackageVersion = "1.0.0.0"

$conversionsParameters += $o
}



$workingDirectory = [System.IO.Path]::Combine($PSScriptRoot, "out")

Write-Host
Write-Host "Here is the job you asked"
Write-Host "========================="
Write-Host "- Packaging all MSIs of the folder '$FolderContainingMSIs'"
Write-Host "- Using the following VMs: "
foreach ($o in $virtualMachines) {
Write-Host "`t" $o.Name
}
Write-Host "- Using the publisher name : '$publisherName'"
Write-Host
Write-Host "Press ENTER continue or CTRL+C to stop here" -ForegroundColor Yellow
Read-Host


RunConversionJobs -conversionsParameters $conversionsParameters -virtualMachines $virtualMachines -remoteMachines $remoteMachines $workingDirectory

SignAndDeploy "$workingDirectory\MSIX"
26 changes: 23 additions & 3 deletions Scripts/BatchConversion/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ Supporting scripts:
2. sign_deploy_run.ps1 - Sign resulting packages
3. run_job.ps1 - Attempt to run the packages locally for initial validation

Usage:
Edit the file entry.ps1 with the parameters of your virtual/remote machines and installers you would like to convert.
Run: entry.ps1
## Package specified MSIs locally or on virtual/remote machines
The script point is *entry.ps1*

**Note:** Edit the file entry.ps1 with the parameters of your virtual/remote machines and installers you would like to convert.

**Run:**

`.\entry.ps1`


## Packages all MSIs of a folder on multiple virtual machines
The script is *ParallelPackaging.ps1*. It takes 3 parameters:
- VMNames = Names of the local virtual machines on which we run the packaging in parallel. The names are comma separated
- FolderContainingMSIs - Local full path name of the folder containing all MSIs to package
- publisherName - Full name of the publisher which has to be the same as the signing certificate like `CN=Contoso Software (FOR LAB USE ONLY), O=Contoso Corporation, C=US`


**Note:** In order to perform a checkpoint/restore between each packaging and have a clean VM each time you have to uncomment the commented line of the script *run_job.js1*.


**Exemple:**

`.\ParallelPackaging.ps1 -VMNames MSIXVM01,MSIXVM02 -FolderContainingMSIs C:\Temp\FolderWithMSIs\ -publisherName "Contoso Software (FOR LAB USE ONLY), O=Contoso Corporation, C=US"`
12 changes: 6 additions & 6 deletions Scripts/BatchConversion/run_job.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ try
{
if ($vmName -and -not (Get-VMSnapshot -Name $initialSnapshotName -VMName $vmName -ErrorAction SilentlyContinue))
{
#Write-Host "Creating VM snapshot for $($vmName): $initialSnapshotName"
#Checkpoint-VM -Name $vmName -SnapshotName "$initialSnapshotName"
Write-Host "Creating VM snapshot for $($vmName): $initialSnapshotName"
Checkpoint-VM -Name $vmName -SnapshotName "$initialSnapshotName"
}

MsixPackagingTool.exe create-package --template $templateFilePath --machinePassword $machinePassword

if ($vmName)
{
#Checkpoint-VM -Name $vmName -SnapshotName "AfterMsixConversion_Job$jobId"
#Write-Host "Creating VM snapshot for $($vmName): AfterMsixConversion_Job$jobId"
#Restore-VMSnapshot -Name "$initialSnapshotName" -VMName $vmName -Confirm:$false
#Write-Host "Restoring VM snapshot for $($vmName): $initialSnapshotName"
Checkpoint-VM -Name $vmName -SnapshotName "AfterMsixConversion_Job$jobId"
Write-Host "Creating VM snapshot for $($vmName): AfterMsixConversion_Job$jobId"
Restore-VMSnapshot -Name "$initialSnapshotName" -VMName $vmName -Confirm:$false
Write-Host "Restoring VM snapshot for $($vmName): $initialSnapshotName"
}
}
finally
Expand Down