Package.psd1

About

This about file contains information about using hashtables and PSD1 files to configure Merge-Script. These psd1 files are also used by PowerShell Tools for Visual Studio Code.

Config File Schema

1
@{
2
Root = 'c:\Users\Adam\Desktop\service.ps1' # Root script to package. This is the main entry point for the package.
3
OutputPath = 'c:\Users\Adam\Desktop\out' # The output directory for the packaging process.
4
Package = @{
5
Enabled = $true # Whether to package as an executable.
6
Obfuscate = $false # Whether to obfuscate the resulting executable.
7
HideConsoleWindow = $false # Whether to hide the console window. Only valid for console applications.
8
# The target .NET Framework version. You will need the .NET Developer Pack for this version installed on your machine.
9
# If target PowerShell 7, you can also use netcoreapp31 here
10
DotNetVersion = 'v4.6.2'
11
FileVersion = '1.0.0' # The output file version
12
FileDescription = '' # The output file description
13
ProductName = '' # The output file product name
14
ProductVersion = '' # The output file product version.
15
Copyright = '' # The output file copyright
16
RequireElevation = $false # Whether to require elevation when running the executable. Only valid for console applications.
17
ApplicationIconPath = '' # The path to the application icon to use for the executable.
18
PackageType = 'Console' # The type of executable to generate. Valid values are Service or Console.
19
ServiceName = "" # The name of the service if the package type is Service.
20
ServiceDisplayName = "" # The display name of the service if the package type is Service.
21
HighDPISupport = $true # Whether to enable high DPI support for WinForm applications
22
PowerShellArguments = '' # Sets the arguments for the PowerShell process that is hosted within the executable. You can use arguments like -NoExit, -ExecutionPolicy and -NoProfile.
23
Platform = 'x64' # Sets the architecture of the executable. Can be either 'x86' or 'x64'
24
PowerShellVersion = 'Windows PowerShell' # You can specify Windows PowerShell or PowerShell 7 or later versions version (e.g. 7.0.0)
25
RuntimeIdentifier = 'win-x64' # You can specify other runtimes like linux-x64 (See .NET Core runtime identifiers)
26
DisableQuickEdit = $false # Disables the quick edit mode on windows console apps
27
Resources = [string[]]@() # Resources to embed in the output executable
28
}
29
Bundle = @{
30
Enabled = $true # Whether to bundle multiple PS1s into a single PS1. Always enabled when Package is enabled.
31
Modules = $true # Whether to bundle modules into the package
32
}
33
}
34
Copied!

Using a config file

A config file can be used either from within a PowerShell script as a hashtable or imported from a PSD1 file containing the hashtable.

EXAMPLES

It is not required to include all aspects of the config when using Merge-Script. The only required components are Root and OutputPath. Aside from that, anything that is not include will be considered false. This means that in the below example, packaging is disabled but bundling is not. The below operation will not bundle nested modules or required assemblies of any modules it is bundling.
1
Merge-Script -Config @{
2
Root = ".\MyScript.ps1"
3
OutputPath = ".\"
4
Bundle = @{
5
Enabled = $true
6
Modules = $true
7
}
8
}
Copied!

Create console application

Creates a PowerShell console based application that has an application icon and hides the console window.
1
@{
2
Root = 'c:\Users\Adam\Desktop\form.ps1'
3
OutputPath = 'c:\Users\Adam\Desktop\out'
4
Package = @{
5
Enabled = $true
6
HideConsoleWindow = $true
7
DotNetVersion = 'v4.6.2'
8
ApplicationIconPath = 'C:\users\adam\desktop\icon.ico'
9
}
10
}
11
Copied!

Create a service

Creates a PowerShell service based on the service.ps1 file and outputs to the out directory on the desktop. It will use the .NET 4.6.2 Developer Pack. The service name will be PSService and the display name will be PowerShell Service.
For more information on services, see the Package as Service section.
1
@{
2
Root = 'c:\Users\Adam\Desktop\service.ps1'
3
OutputPath = 'c:\Users\Adam\Desktop\out'
4
Package = @{
5
Enabled = $true
6
DotNetVersion = 'v4.6.2'
7
FileVersion = '1.0.0'
8
FileDescription = ''
9
ProductName = ''
10
ProductVersion = ''
11
Copyright = ''
12
PackageType = 'Service'
13
ServiceName = "PSService"
14
ServiceDisplayName = "PowerShell Service"
15
}
16
}
17
Copied!
After building a service, you can install the service with the --install parameter of your service's executable. To uninstall a service, use the --uninstall parameter.

Bundle PowerShell Core Engine with your Script

Creates an executable that contains the PowerShell Core engine. This executable does not require the target machine have PowerShell Core or .NET Core installed. The size of the executable will be considerably larger than a typical Merge-Script executable.
1
@{
2
Root = 'c:\Users\Adam\Desktop\script.ps1'
3
OutputPath = 'c:\Users\Adam\Desktop\out'
4
Package = @{
5
Enabled = $true
6
DotNetVersion = 'netcoreapp3.1'
7
PowerShellVersion = "7.1.3"
8
}
9
Bundle = @{
10
Enabled = $true
11
Modules = $true
12
}
13
}
Copied!

Bundle resources in a WPF application

Embeds the image.png file within the application so you can reference it in your XAML. This file resides in the same folder as window.ps1.
1
@{
2
Root = 'c:\Users\Adam\Desktop\Window.ps1'
3
OutputPath = 'c:\Users\Adam\Desktop\out'
4
Package = @{
5
Enabled = $true
6
Resources = @("image.png")
7
}
8
Bundle = @{
9
Enabled = $true
10
Modules = $true
11
}
12
}
Copied!
In the XAML, you can reference the image like this.
1
<Window x:Class="WpfApp1.MainWindow"
2
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6
xmlns:local="clr-namespace:WpfApp1"
7
mc:Ignorable="d"
8
Title="MainWindow" Height="450" Width="800">
9
<Grid>
10
<Image Source="image.png" />
11
</Grid>
12
</Window>
13
Copied!
Last modified 3mo ago