How to install the MSI package using PowerShell DSC?


To install the MSI package using DSC, we need to use the DSC resource “Package”. Let see which properties are available for this resource.

PS C:\> Get-DscResource -Name Package | Select -ExpandProperty Properties

Name PropertyType IsMandatory Values
---- ------------ ----------- ------
Name [string] True {}
Path [string] True {}
ProductId [string] True {}
Arguments [string] False {}
Credential [PSCredential] False {}
DependsOn [string[]] False {}
Ensure [string] False {Absent, Present}
LogPath [string] False {}
PsDscRunAsCredential [PSCredential] False {}
ReturnCode [UInt32[]] False {}

Name, Path, and ProductID parameters are mandatory for this DSC resource.

The best way to retrieve the above details is to install the sample package on the test machine and then get the details. We will use here the 7Zip MSI package installed on one computer.

Get-Package 7-zip* | fl *

From the above output, we can grab here the name of the Package after installation, ProductID (i.e. ProductCode).

Configuration Install7zip{
   Node @("LabMachine2k16","AD"){
      Package 7zip{
         Name = '7-Zip 19.00 (x64 edition)'
         ProductId = '23170F69-40C1-2702-1900-000001000000'
         Path = '\ad\shared\7z1900-x64.msi'
         Ensure = 'Present'
      }
   }
}

In the above example, the source package is located at the source location and we want to install 7zip on the two nodes.

To generate the MOF file at the specific location so we can use them later to start the configuration,

Install7zip -OutputPath C:\Temp\7zipInstall -Verbose

Output

Once the MOF file is generated, we can start the configuration to apply DSC,

Start-DscConfiguration -Path C:\Temp\7zipInstall -Wait -Force -Verbose

Once the above command runs successfully, check if the configuration is applied or not using,

Test-DscConfiguration -Path C:\Temp\7zipInstall

You should get output like below, which shows that both the servers are in the desired state, which means the MSI package is installed.

If the InDesiredState property is false, it means the server has missed the configuration.

Updated on: 28-Apr-2021

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements