Search code examples
windows-installerdsc

Pass environment variable to INSTALLDIR in msi


I am trying to write a PowerShell DSC configuration and have the following code:

Package RapidCRC
{
    Ensure = "Present"
    Path  = "C:\Repo\RapidCRC.Unicode.v0.3.27.x64\RapidCRC-Setup-0.3.27-x64.msi"
    Name = "RapidCRC (x64) 0.3.27"
    ProductId = "{27A6AB13-B66B-4AB8-BDA1-313477475F6A}"
    Arguments = 'INSTALLDIR="C:\Program Files\Utilities\RapidCRC.Unicode" ALLUSERS=2 ARPSYSTEMCOMPONENT=0'
}

I would like to pass C:\Program Files as an environment variable. I tried the following:

Arguments = 'INSTALLDIR="%ProgramFiles%\Utilities\RapidCRC.Unicode" ALLUSERS=2 ARPSYSTEMCOMPONENT=0'

Arguments = 'INSTALLDIR="[ProgramFiles64Folder]Utilities\RapidCRC.Unicode" ALLUSERS=2 ARPSYSTEMCOMPONENT=0'

but they do not work. Any help appreciated.


Solution

  • You are looking at PowerShell scripts. So, you can use $env:ProgramFiles in your DSC configuration script:

    Package RapidCRC
    {
        Ensure = "Present"
        Path  = "C:\Repo\RapidCRC.Unicode.v0.3.27.x64\RapidCRC-Setup-0.3.27-x64.msi"
        Name = "RapidCRC (x64) 0.3.27"
        ProductId = "{27A6AB13-B66B-4AB8-BDA1-313477475F6A}"
        Arguments = "INSTALLDIR=`"$($env:ProgramFiles)\Utilities\RapidCRC.Unicode`" ALLUSERS=2 ARPSYSTEMCOMPONENT=0"
    }
    

    SIDE NOTE: Please pay attention to backticks used in Argument parameter.