Real life examples of the xPackage Resource

This topic contains 5 replies, has 6 voices, and was last updated by  Dude 9 months ago.

  • Author
  • #18915

    Rob Cannon

    Is there a source of real examples for xPackage? I think some of these configurations are complicated enough that a repository (similar to Chocolatey) would be a good idea.

    For instance, I am trying to figure out the right parameters for installing .NET Framework 4.5.2. Here is what I have so far:

        xPackage DotNetFramework452
            Ensure = 'Present'
            Name = ''
            Path  = '\\isgfile01\ServerSetup\.Net 4.5.2\NDP452-KB2901907-x86-x64-AllOS-ENU.exe'
            ProductId = ''
            Arguments = '/q /norestart'
            ReturnCode = @(0,3010)
            InstalledCheckRegKey = 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full'
            InstalledCheckRegValueName = 'Release'
            InstalledCheckRegValueData = '379893'

    But some questions:

    1) What should Name be? Does this have to match something in the registry somewhere?
    2) Same for ProductId
    3) How do I detect the 3020 return code and indicate that a reboot is needed (maybe DSC picks that up from somewhere else).

    In general, I think the .NET 4.5.2 package is a tricky one because it behaves differently depending on which OS you install it. In Win 8.1/Server2012R2 it is installed as a Windows update (KB2934520). But in earlier servers (like 2008R2), it installed into the Programs and Features list and probably has a ProductId there.

    Anyway, this stuff is sparsely documented and some real world examples of specific products would be helpful.

  • #18956

    Don Jones

    I think your long-term solution will be OneGet.

    Name is arbitrary, in most of the cases I've seen. ProductID is the ProductID from the Windows Installer database. And, the package resource ought to be picking up on the reboot requirement itself and setting the appropriate DSC flag.

    The Package resource is particular is extremely hit or miss, in my experience. In most cases, I've had to write a custom Script resource to deal with these things. I'm hoping that with OneGet, packages will become a bit more standardized and easier to manage this way.

  • #19731

    Michael Craig

    Did you ever get this to work for you? I'm trying to write a custom script resource to install .net 4.5.2 and can't get DSC to invoke the installer. Hoping you have an easier answer there.



    Here is an example of my SetScript, the commands work if I execute them in a powershell window, but the installer never gets executed when run by DSC:

    SetScript = {
    $filename = "NDP452-KB2901907-x86-x64-AllOS-ENU.exe"
    $httpdownload = ""
    $NetBuildVersion = "379893"

    $DnsDomain = (Get-WmiObject Win32_ComputerSystem).domain

    write-verbose "DnsDomain: $DnsDomain"
    sleep 5

    switch -wildcard ($DnsDomain)
    "lab*" { $binpath="\\server\public\FileShare\dotNetRedist\$filename"}
    "labtest*" { $binpath="\\server2\DeploymentAutomation\bin\hotfixes\$filename"}
    default {$binpath="\\n\a"}

    if (!(test-path $binpath)){ invoke-webrequest $httpdownload -OutFile C:\binroot\$filename;$binpath="c:\binroot\$filename"}

    write-verbose "Install Net 4.5.2 from $binpath"
    write-verbose "Executing $binpath /q /norestart"

    #Start-Process -FilePath $binpath -ArgumentList "/q /norestart" -Wait
    #Invoke-Expression -Command "$binpath /q /norestart"
    &$binpath "/q" "/norestart"

    while ($isInstalled -ne $true){

    if (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' | %{$_ -match 'Release'}){
    if (( Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full').Release -le $NetBuildVersion){$isInstalled = $false}else{$isInstalled=$true}
    write-verbose "Net 4.5.2 Installed Yet?: $isInstalled"
    sleep 5


  • #21658

    Peter Myklebust

    Perhaps a bit late, but this worked well for me:

    $proc = Start-Process -FilePath $env:TEMP\$file -ArgumentList "/quiet /norestart /log $env:TEMP\$Version.log" -PassThru -Wait
                    0 {
                        #All good
                    1603 {
                        throw "Failed installation"
                    1641 {
                        #restart required
                        $global:DSCMachineStatus = 1                
                    3010 {
                        #restart required
                        $global:DSCMachineStatus = 1                
                    5100 {
                        throw "The user's computer does not meet system requirements."
                    default {
                        throw "Unknown exit code $($proc.ExitCode)"
  • #21709

    Ryan Young

    I'll just throw this into here in case Rob insists on using the xpackage resource:

  • #57857


    For a working example on how to install the .NET 4.6.1 framework using the xPackage DSC resource please see below.

    configuration DotNET461ConfigurationDefinition
    	$ErrorActionPreference = "Stop"
    	Import-DSCResource -ModuleName xPSDesiredStateConfiguration;
    	Node localhost
            # The .NET 4.6.1 Framework installation. For more information about checking the installation of .NET frameworks see:
            # MSDN How to: Determine Which .NET Framework Versions Are Installed
        	xPackage NetFramework461
                Name = "dotNETFramework461"
                ProductId = ""
                Path = "C:\installers\NDP461-KB3102436-x86-x64-AllOS-ENU.exe"
                InstalledCheckRegKey = "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full"
                InstalledCheckRegValueName = "Release"
                InstalledCheckRegValueData = "394271"
                Arguments = "/q"
    DotNET461ConfigurationDefinition -output "." 
    #Test-DscConfiguration -Path .\DotNET461ConfigurationDefinition -Verbose
    Start-DscConfiguration -Path .\DotNET461ConfigurationDefinition -Force -Wait -Verbose 

You must be logged in to reply to this topic.