PSMSI には、任意のファイルとディレクトリ構造を含めることができる MSI パッケージを作成するためのコマンドレットが含まれています。また、カスタム EULA とイメージを含めることでインストーラー インターフェイスをカスタマイズする機能も含まれています。
PSMSIでインストーラーの作成を開始するには、PSMSIモジュールの最新バージョンをダウンロードする必要があります。これはでインストールできます。
Install-Module
Install-Module PSMSI
このモジュールは、Wix ツールセットの v3 に基づいています。このモジュールで達成できることは他にもたくさんあります。主にWiX XMLを作成し、WiXツールを実行してMSIを生成します。私たちはPRや問題に非常にオープンです。追加できる機能については、WiXのドキュメントを確認してください。
コマンドレットは、インストーラーを生成するために使用されます。インストール用のディレクトリとファイルを含めることができます。最初のステップは、インストーラーの基本パラメーターを定義することです。
New-Installer
製品パラメータとアップグレードコードパラメータは必須です。アップグレードコードは、製品の各バージョンで同じままである必要があり、他の製品から一意である必要がある GUID です。
New-Installer -ProductName "My First Product" -UpgradeCode '1a73a1be-50e6-4e92-af03-586f4a9d9e82'
New-Installer コマンドレットの Content パラメーター内に、エンド ユーザーのコンピューターにインストールするためのルート ディレクトリを含める必要があります。ルートディレクトリは、事前定義されたディレクトリである必要があります。新しいインストーラーディレクトリのパラメーター セットの 1 つは、ターゲット ルート ディレクトリを選択するために使用できる定義済みのディレクトリ パラメーターを定義します。
New-InstallerDirectory -PredefinedDirectory "LocalAppDataFolder"
オプションで、ルートディレクトリ内のネストされたディレクトリを指定できるようになりました。存在しない場合は作成され、アンインストール時に削除されます。
New-InstallerDirectory -DirectoryName "My First Product"
最後に、ディレクトリ内にファイルを含めることができます。新しいインストーラー ファイル コマンドレットは、インストールするファイルへのパスを持つ Source パラメーターを受け入れます。
New-InstallerFile -Source .\MyTextFile.txt
このインストーラーの完全なスクリプトは次のようになります。
New-Installer -ProductName "My First Product" -UpgradeCode '1a73a1be-50e6-4e92-af03-586f4a9d9e82' -Content {
New-InstallerDirectory -PredefinedDirectory "LocalAppDataFolder" -Content {
New-InstallerDirectory -DirectoryName "My First Product" -Content {
New-InstallerFile -Source .\license.txt
}
}
} -OutputDirectory (Join-Path $PSScriptRoot "output")
上記のスクリプトを実行すると、出力ディレクトリに WXS、WXSOBJ、および MSI ファイルが生成されます。MSI は、エンド ユーザーに提供する必要がある唯一のファイルです。WXS ファイルと WXSOBJ ファイルは、これらのインストーラーを生成するために使用される Windows インストーラー XML ツールキットの成果物です。
あなたは使用することができますのパラメータデフォルトからインストールに変更しますインストール。
-RequriesElevation
New-Installer
PerUser
PerMachine
次の例では、プログラム ファイル フォルダーにインストールするインストーラーを作成します。
New-Installer -ProductName "My First Product" -UpgradeCode '1a73a1be-50e6-4e92-af03-586f4a9d9e82' -Content {
New-InstallerDirectory -PredefinedDirectory "ProgramFilesFolder" -Content {
New-InstallerDirectory -DirectoryName "My First Product" -Content {
New-InstallerFile -Source .\license.txt
}
}
} -OutputDirectory (Join-Path $PSScriptRoot "output") -RequiresElevation
[プログラムの追加と削除] 内に表示されるアプリケーション アイコンは、を使用して定義できます。
AddRemoveProgramsIcon
New-Installer
New-Installer -Product "My First Product" -UpgradeCode '1a73a1be-50e6-4e92-af03-586f4a9d9e82' -Content {
New-InstallerDirectory -PredefinedDirectory "ProgramFilesFolder" -Content {
New-InstallerDirectory -DirectoryName "My First Product" -Content {
New-InstallerFile -Source .\license.txt
}
}
} -OutputDirectory (Join-Path $PSScriptRoot "output") -AddRemoveProgramsIcon "icon.ico"
値は、アップグレードが正常に機能するように静的である必要があります。アップグレード コードを on で定義します。
UpgradeCode
New-Installer
New-Installer -ProductName "My First Product" -UpgradeCode '1a73a1be-50e6-4e92-af03-586f4a9d9e82' -Content {
New-InstallerDirectory -PredefinedDirectory "ProgramFilesFolder" -Content {
New-InstallerDirectory -DirectoryName "My First Product" -Content {
New-InstallerFile -Source .\license.txt
}
}
} -OutputDirectory (Join-Path $PSScriptRoot "output")
インストーラーのバージョンは、のパラメーターを使用して設定されます。バージョンを増やし、アップグレードコードを同じに保つことで、アップグレードを提供できます。
Version
New-Installer
バージョンのデフォルトは 1.0 です。
New-Installer -ProductName "My First Product" -UpgradeCode '1a73a1be-50e6-4e92-af03-586f4a9d9e82' -Content {
New-InstallerDirectory -PredefinedDirectory "ProgramFilesFolder" -Content {
New-InstallerDirectory -DirectoryName "My First Product" -Content {
New-InstallerFile -Source .\license.txt
}
}
} -OutputDirectory (Join-Path $PSScriptRoot "output") -Version 2.0
カスタム アクションを使用すると、インストール中およびアンインストール中に PowerShell スクリプトを実行できます。スクリプトをファイルとしてインストーラーに含める必要があります。のパラメータを使用して、実行するPS1ファイルを参照します。
FileId
New-InstallerCustomAction
たとえば、ID という名前のスクリプトがあるとします。
MyCustomAction.ps1
CustomAction
New-InstallerFile -Source .\myCustomAction.ps1 -Id 'CustomAction'
その後、そのスクリプトをインストール中にカスタムアクションとして使用できます。
New-InstallerCustomAction -FileId 'CustomAction' -RunOnInstall
PowerShell.exe とスクリプトの両方に引数を渡すことができます。パラメーターは、カスタム引数を PowerShell に渡します.exe (-NoProfile など)。パラメーターは、スクリプト自体に渡す引数を定義します。
Arguments
ScriptArguments
これにより、PowerShell .exe の終了コードがチェックされます。終了コードが 0 以外の場合は、インストールが失敗します。
インストール中にカスタムアクションを実行します。
アンインストール中にカスタムアクションを実行します。
を使用してディレクトリとファイルを作成できますand。ディレクトリは、MSI によって提供される定義済みのディレクトリのいずれかで始まる必要があります。
New-InstallerDirectory
New-InstallerFile
のパラメータを使用して、インストールのルートフォルダを定義します。などのディレクトリを使用できます。
PredefinedDirectory
New-InstallerDirectory
Program Files
AppData
CommonAppData
カスタムフォルダは、事前定義されたディレクトリ内に表示されます。フォルダをネストしてフォルダツリーを作成できます。その後、フォルダーにファイルを含めることができます。のパラメータを使用してディレクトリを作成します。含めるフォルダーまたはファイルを指定するために使用します。
DirectoryName
New-InstallerDirectory
Content
含めるプロパティonエンドユーザーは、インストール中にディレクトリを選択できるようにします。
Configurable
New-InstallerDirectory
New-InstallerDirectory -DirectoryName "My First Product" -Content {
New-InstallerFile -Source .\license.txt
} -Configurable
ファイルは、現在の場所と ID によって定義されます。パラメーターは、含めるファイルを識別する必要があります。ツリー内の場所は、ディスク上のどこにインストールされるかを定義します。
Source
New-InstallerDirectory
New-InstallerDirectory -DirectoryName "My First Product" -Content {
New-InstallerFile -Source .\license.txt
}
ショートカットは、を使用してインストーラーに対して定義できます。を使用してショートカットの場所を定義し、Id でファイルを参照します。
New-InstallerShortcut
New-InstallerDirectory
たとえば、ID でファイルを定義するには、のパラメーターを含めます。
Id
New-InstallerFile
New-InstallerFile -Source .\MyTextFile.txt -Id "myTestFile"
次に、ディレクトリ内のショートカットを定義し、ID でファイルを参照します。
New-InstallerDirectory -PredefinedDirectory "DesktopFolder" -Content {
New-InstallerShortcut -Name "My Test File" -FileId "myTestFile"
}
ショートカットの作業ディレクトリを設定するには、フォルダの ID を指定します。次の例では、作業ディレクトリをインストールディレクトリの ID に設定します。
New-Installer -ProductName "MyImage" -UpgradeCode (New-Guid) -Version 1.0.0 -Content {
New-InstallerDirectory -PredefinedDirectoryName ProgramFilesFolder -Content {
New-InstallerDirectory -DirectoryName 'MyDir' -Id 'MyDir' -Content {
New-InstallerFile -Id 'Image' -Source 'services.png'
}
}
New-InstallerDirectory -PredefinedDirectoryName DesktopFolder -Content {
New-InstallerShortcut -Name 'Test' -FileId 'Image' -WorkingDirectoryId 'MyDir'
}
} -OutputDirectory .\installer -RequiresElevation
を使用してインストーラーのユーザーインターフェイスをカスタマイズできますのパラメーターと一緒に。
UserInterface
New-Installer
New-InstallerUserInterface
ユーザーインターフェイスには、インストーラーのカスタムグラフィックとEULAを含めることができます。
$UserInterface = New-InstallerUserInterface -Eula (Join-Path $PSScriptRoot 'eula.rtf') -TopBanner (Join-Path $PSScriptRoot "banner.png") -Welcome (Join-Path $PSScriptRoot "welcome.png")
その他の無料ツールについては、アイアンマン・ソフトウェアの無料ツール・インデックスをご覧ください。