다음을 통해 공유


Installing MSI packages using PowerShell Desired State Configuration

Demo

In this Wiki let's explore Package Resource to install 7-Zip MSI in Windows 2012 Server.

Syntax

Get-DscResource -Name Package -Syntax

Output

DSC Code

Configuration Install7Zip
{
    Node $env:ComputerName
    {
        Package Install7Zip
        {
            Ensure = 'Present'
            Name = '7-Zip 9.20 (x64 edition)'
            Path = 'C:\MyOfficePackages\7z920-x64.msi'
            ProductId = '23170F69-40C1-2702-0920-000001000000'

        }
    }
}

Install7Zip -OutputPath C:\Install7Zip

Start-DscConfiguration -Path C:\Install7Zip -wait -verbose -Force

MOF

/*
@TargetNode='DSC'
@GeneratedBy=ChenV
@GenerationDate=12/24/2014 13:59:26
@GenerationHost=DSC
*/

instance of MSFT_PackageResource as $MSFT_PackageResource1ref
{
ResourceID = "[Package]Install7Zip";
 Path = "C:\\MyOfficePackages\\7z920-x64.msi";
 Ensure = "Present";
 ProductId = "23170F69-40C1-2702-0920-000001000000";
 SourceInfo = "::5::9::Package";
 Name = "7-Zip 9.20 (x64 edition)";
 ModuleName = "PSDesiredStateConfiguration";
 ModuleVersion = "1.0";

 ConfigurationName = "Install7Zip";

};
instance of OMI_ConfigurationDocument
{
 Version="2.0.0";
 MinimumCompatibleVersion = "1.0.0";
 CompatibleVersionAdditionalProperties= {"Omi_BaseResource:ConfigurationName"};
 Author="ChenV";
 GenerationDate="12/24/2014 13:59:26";
 GenerationHost="DSC";
 Name="Install7Zip";
};

Result

Summary

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[]] ]
}