PowerShell DSC – How to install a MSI

PowerShell DSC – DSC is a new management platform in Windows PowerShell that enables deploying and managing configuration data for software services and managing the environment in which these services run.

Requirement – How to install MSI using PowerShell DSC?

Solution –

Suppose, we have xyz.client.msi that needs to be installed on target machine. For this example, I have considered installing it on the localhost. To install it on the target server, PS remoting needs to be enabled and WinRM port configured for HTTP communication using below PowerShell commands

a) Enable-PSRemoting –Force

b) winrm quickconfig –transport:http

I wrote below script to make it happen:

Configuration ApplicationInstall

Package AppInstall
    Ensure = "Present"
    Path = "E:\Software\xyz.Client.msi"
    Name = "TestPkg"
    ProductId = "{23FB7DAE-F831-4F6F-854B-2B28A7DD3C98}"
    Arguments = "AllUsers=1"

ApplicationInstall –Output C:\ApplicationInstall

Start-DscConfiguration -Path C:\ApplicationInstall -ComputerName localhost -Force -Verbose -wait

Explanation –

First thing, we need to create a Configuration with the key word “Configuration”.

Next step is to create the “Package” resource. It has many properties as explained below:

Package [string] #ResourceName
Name = [string] #This is Mandatory Property
Path = [string] #This is Mandatory Property
ProductId = [string] #This is Mandatory Property
[ Arguments = [string] ]
[ Credential = [PSCredential] ]
[ DependsOn = [string[]] ]
[ Ensure = [string] { Absent | Present } ]
[ LogPath = [string] ]
[ ReturnCode = [UInt32[]] ]

Apart from Mandatory parameters, I have used:

1) Ensure parameter –

        “Present” – Means the MSI should be present, if not, it will install it.

        “Absent” – Means the MSI should not be present, if present, it will uninstall it.

2) Arguments – You can pass any argument that you want to pass with MSI.

Once the Package is written, we need to execute the configuration with the following command and it will create the MOF (Managed Object Format) file and will keep it at C:\ApplicationInstall folder:

ApplicationInstall –Output C:\ApplicationInstall


Content of MOF file –


MOF files are a convenient way to change WMI settings and to transfer WMI objects between computers. The contents of MOF files only become effective when the files are compiled.

Now to compile MOF file, I ran the below command:

Start-DscConfiguration -Path C:\ApplicationInstall -ComputerName localhost -Force -Verbose –wait

Output –


If you re-ran the above command, it will say, “the package is already installed”.

If you want to uninstall the application, just change the “Ensure” property of the package to “Absent”, and then execute the configuration to create the MOF file and then compile it. It will then uninstall the application.

—End of Article—


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s