2

I'm trying to write a desired state configuration that installs a package via PackageManagement (aka OneGet). The package, "notepadplusplus", comes from the Chocolatey repository but I want to use PackageManagement rather than the Chocolatey client. I couldn't find a DSC resource to do it, so I'm using a Script resource.

DSC runs without errors and Notepad++ shows up in the packages list but never actually gets installed (Notepad++.exe is nowhere on the system).

I'm running on a Windows 10 VM.

Here's a simplified example of what I'm doing. Anyone spot what I'm doing wrong?

dscConfig.ps1

Configuration BuildProvisioning
{
    param(
        [string[]]$computerName="localhost"
    )
    Import-DscResource -ModuleName PSDesiredStateConfiguration

    Node $computerName
    {
        Script PackageManagementTest
        {
            SetScript = {
                Get-PackageProvider NuGet -Force | Out-Null
                Get-PackageProvider Chocolatey -Force | Out-Null
                Install-Package notepadplusplus -Force
            }
            TestScript = { $false }
            GetScript  = { @{} }
        }
    }
}

And here is how I'm kicking it off on the VM

. .\dscConfig.ps1
BuildProvisioning
winrm quickconfig -quiet
Start-DscConfiguration -Verbose -Force -Wait -ComputerName "localhost" -Path ".\BuildProvisioning\"
Anthony Mastrean
  • 21,850
  • 21
  • 110
  • 188
Vimes
  • 10,577
  • 17
  • 66
  • 86

1 Answers1

1

It's caused by this issue in OneGet, where you have to enable scrips via Set-ExecutionPolicy or OneGet fails while reporting success. This happens even if you set the execution policy before starting DSC. It has to be set within your DSC configuration. Apparently, it's running in a new session that doesn't inherit the execution policy.

Here's a simple fix where I set the execution policy before the package installation:

Configuration BuildProvisioning
{
    param(
        [string[]]$computerName="localhost"
    )
    Import-DscResource -ModuleName PSDesiredStateConfiguration

    Node $computerName
    {
        Script ExecutionPolicy
        {
            SetScript = {
                Set-ExecutionPolicy RemoteSigned -Force
            }
            TestScript = { $false }
            GetScript  = { @{} }
        }

        Script PackageManagementTest
        {
            SetScript = {
                Get-PackageProvider NuGet -Force | Out-Null
                Get-PackageProvider Chocolatey -Force | Out-Null
                Install-Package notepadplusplus -Force
            }
            TestScript = { $false }
            GetScript  = { @{} }
            DependsOn = "[Script]ExecutionPolicy"
        }
    }
}

Instead of using a Script resource to set the execution policy, you might try the xPowerShellExecutionPolicy resource. Install instructions here and here's a sample DSC configuration.

Vimes
  • 10,577
  • 17
  • 66
  • 86