Search code examples
powershelldsc

Powershell DSC: How to download and install MSI


Using Powershell DSC how do I download and install msi. I the references I have seen so far this link https://blogs.msdn.microsoft.com/brian_farnhill/2015/03/15/using-dsc-to-download-from-azure-file-storage-to-an-azure-vm/. But I can only be used for shared folder no to http.

        File DownloadWebPi
        {
            DestinationPath = $PSScriptRoot
            Ensure ="Present"
            SourcePath = "http://go.microsoft.com/fwlink/?LinkId=287166"
            Type = "File"
        }

Solution

  • Script DownloadMsi
    {
                GetScript = 
                {
                    @{
                        GetScript = $GetScript
                        SetScript = $SetScript
                        TestScript = $TestScript
                        Result = ('True' -in (Test-Path c:\Somepath\install.msi))
                    }
                }
    
                SetScript = 
                {
                    Invoke-WebRequest -Uri "http://go.microsoft.com/fwlink/?LinkId=287166" -OutFile "c:\Somepath\install.msi"
                }
    
                TestScript = 
                {
                    $Status = ('True' -in (Test-Path c:\Somepath\install.msi))
                    $Status -eq $True
                }
            }
    

    And then next write next part to install msi which depends on this section. Also don't use $PSScriptRoot as I believe this executes in system32.