Uninstall the MSI file with the given ID at the given path
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'
}
}
}
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for