Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Description
This example shows how you can use the MsiPackage resource to ensure a package is installed.
With Ensure set to Present, ProductID set to {DEADBEEF-80C6-41E6-A1B9-8BDB8A05027F}, and
Path set to https://contoso.com/example.msi, the resource installs the example.msi package
if it isn't already installed.
If the package isn't installed, the resource downloads it from https://contoso.com/example.msi
when the resource enforces the desired state. If the download fails, the resource throws an
exception.
With Invoke-DscResource
This script shows how you can use the MsiPackage resource with the Invoke-DscResource cmdlet to
ensure a package on a web URI is installed.
[CmdletBinding()]
param()
begin {
$SharedParameters = @{
Name = 'MsiPackage'
ModuleName = 'PSDscResource'
Properties = @{
ProductId = '{DEADBEEF-80C6-41E6-A1B9-8BDB8A05027F}'
Path = 'https://contoso.com/example.msi'
Ensure = 'Present'
}
}
$NonGetProperties = @(
'Ensure'
)
}
process {
$TestResult = Invoke-DscResource -Method Test @SharedParameters
if ($TestResult.InDesiredState) {
$QueryParameters = $SharedParameters.Clone()
foreach ($Property in $NonGetProperties) {
$QueryParameters.Properties.Remove($Property)
}
Invoke-DscResource -Method Get @QueryParameters
} else {
Invoke-DscResource -Method Set @SharedParameters
}
}
With a Configuration
This snippet shows how you can define a Configuration with a MsiPackage resource block to ensure
a package on a web URI is installed.
Configuration InstallPackageFromHttps {
Import-DscResource -ModuleName 'PSDscResources'
Node localhost {
MsiPackage ExampleMsiPackage {
ProductId = '{DEADBEEF-80C6-41E6-A1B9-8BDB8A05027F}'
Path = 'https://contoso.com/example.msi'
Ensure = 'Present'
}
}
}