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 isn't installed.
With Ensure set to Absent
, ProductID set to {DEADBEEF-80C6-41E6-A1B9-8BDB8A05027F}
, and
Path set to file://Examples/example.msi
, the resource uninstalls the example.msi
package if
it's installed.
If the package is installed and the example.msi
file doesn't exist, the resource throws an
exception when it enforces the desired state.
With Invoke-DscResource
This script shows how you can use the MsiPackage
resource with the Invoke-DscResource
cmdlet to
ensure a package on the local file system isn't installed.
[CmdletBinding()]
param()
begin {
$SharedParameters = @{
Name = 'MsiPackage'
ModuleName = 'PSDscResource'
Properties = @{
ProductId = '{DEADBEEF-80C6-41E6-A1B9-8BDB8A05027F}'
Path = 'file://Examples/example.msi'
Ensure = 'Absent'
}
}
$NonGetProperties = @(
'Ensure'
'MembersToInclude'
)
}
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 the local file system isn't installed.
Configuration UninstallPackageFromFile {
Import-DscResource -ModuleName 'PSDscResources'
Node localhost {
MsiPackage ExampleMsiPackage {
ProductId = '{DEADBEEF-80C6-41E6-A1B9-8BDB8A05027F}'
Path = 'file://Examples/example.msi'
Ensure = 'Absent'
}
}
}