chocolatey-community / Chocolatey

PowerShell Module and DSC Resource for Chocolatey Software
MIT License
43 stars 15 forks source link

DSC ChocolateyPackage error #30

Closed electricJP closed 1 year ago

electricJP commented 5 years ago

Hello,

Considering this DSC usage:

ChocolateyPackage EMCopy 
        {
            Ensure = "Present" 
            Name = "EMCOPY64"
            version = "Latest"
            ChocolateyOptions = @{ source = 'ChocoGL' } 
        }

will result in:

VERBOSE: [SZX-DC01]: LCM:  [ Start  Resource ]  [[ChocolateyPackage]EMCopy]
VERBOSE: [SZX-DC01]: LCM:  [ Start  Test     ]  [[ChocolateyPackage]EMCopy]
VERBOSE: [SZX-DC01]:                            [[ChocolateyPackage]EMCopy] Converting CIMInstance[] to hashtable
VERBOSE: [SZX-DC01]:                            [[ChocolateyPackage]EMCopy] >> Converting CIM Pairs
VERBOSE: [SZX-DC01]:                            [[ChocolateyPackage]EMCopy] Testing whether the Package EMCOPY64 is Installed
Method invocation failed because [System.Management.Automation.PSCustomObject] does not contain a method named 'Where'.
    + CategoryInfo          : InvalidOperation: (Where:) [], CimException
    + FullyQualifiedErrorId : MethodNotFound
    + PSComputerName        : szx-dc01.gameloft.org

VERBOSE: [SZX-DC01]: LCM:  [ End    Test     ]  [[ChocolateyPackage]EMCopy]  in 7.6540 seconds.

if the package is already installed (from Install-ChocolateyPackage), there is no error:

VERBOSE: [SZX-DC01]: LCM:  [ Start  Resource ]  [[ChocolateyPackage]EMCopy]
VERBOSE: [SZX-DC01]: LCM:  [ Start  Test     ]  [[ChocolateyPackage]EMCopy]
VERBOSE: [SZX-DC01]:                            [[ChocolateyPackage]EMCopy] Converting CIMInstance[] to hashtable
VERBOSE: [SZX-DC01]:                            [[ChocolateyPackage]EMCopy] >> Converting CIM Pairs
VERBOSE: [SZX-DC01]:                            [[ChocolateyPackage]EMCopy] Testing whether the Package EMCOPY64 is Installed
VERBOSE: [SZX-DC01]: LCM:  [ End    Test     ]  [[ChocolateyPackage]EMCopy]  in 6.0990 seconds.
VERBOSE: [SZX-DC01]: LCM:  [ Skip   Set      ]  [[ChocolateyPackage]EMCopy]
VERBOSE: [SZX-DC01]: LCM:  [ End    Resource ]  [[ChocolateyPackage]EMCopy]
gaelcolas commented 5 years ago

Thanks, will have a look. How many source do you have configured on that node?

electricJP commented 5 years ago

Only 1 so far. But as choco is global for the system I do prefer list the source I want (tested and created if needed earlier in the DSC)..

gaelcolas commented 5 years ago

Ok. What happens when you run:

Test-ChocolateyPackageIsInstalled -name EMCOPY64 -source ChocoGL -version latest

Can you post the error trace here?

electricJP commented 5 years ago

I guess you mean to run it on a system w/o the installed package. So here it is (notice the difference with -verbose:

PS C:\Windows\system32> Test-ChocolateyPackageIsInstalled -name EMCOPY64 -source ChocoGL -version latest -Verbose
VERBOSE: choco list -r --local-only
VERBOSE: Could not find Package EMCOPY64
VERBOSE: choco list -r -s"ChocoGL"
VERBOSE: No packages match the selection and need Installing.

PackagePresent VersionGreaterOrEqual
-------------- ---------------------
         False                 False

PS C:\Windows\system32> Test-ChocolateyPackageIsInstalled -name EMCOPY64 -source ChocoGL -version latest
Method invocation failed because [System.Management.Automation.PSCustomObject] does not contain a method named 'Where'.
At C:\Program Files\WindowsPowerShell\Modules\chocolatey\0.0.50\Chocolatey.psm1:1418 char:13
+             $UnfilteredResults.Where{
+             ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Where:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

PackagePresent VersionGreaterOrEqual
-------------- ---------------------
         False                 False
gaelcolas commented 5 years ago

Thanks, will look into it. The difference might not be because of -verbose but because of caching... We'll see...

gaelcolas commented 5 years ago

Hi, I think it's fixed. Please try v0.0.58 from the gallery and let me know :)

Thanks

electricJP commented 5 years ago

Sorry, but I get a new error now. Same DSC as above, result=

VERBOSE: [MTL-VD01]: LCM:  [ Start  Set      ]
VERBOSE: [MTL-VD01]: LCM:  [ Start  Resource ]  [[ChocolateyPackage]EMCopy]
VERBOSE: [MTL-VD01]: LCM:  [ Start  Test     ]  [[ChocolateyPackage]EMCopy]
VERBOSE: [MTL-VD01]:                            [[ChocolateyPackage]EMCopy] Converting CIMInstance[] to hashtable
VERBOSE: [MTL-VD01]:                            [[ChocolateyPackage]EMCopy] >> Converting CIM Pairs
VERBOSE: [MTL-VD01]:                            [[ChocolateyPackage]EMCopy] Testing whether the Package EMCOPY64 is Installed
Cannot bind argument to parameter 'Path' because it is null.
    + CategoryInfo          : InvalidData: (:) [], CimException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand
    + PSComputerName        : mtl-vd01.gameloft.org

Cannot bind argument to parameter 'Path' because it is null.
    + CategoryInfo          : InvalidData: (:) [], CimException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand
    + PSComputerName        : mtl-vd01.gameloft.org

VERBOSE: [MTL-VD01]: LCM:  [ End    Test     ]  [[ChocolateyPackage]EMCopy]  in 3.6270 seconds.

from the server itself:

PS C:\Windows\system32> Get-InstalledModule -Name chocolatey

Version              Name                                Repository           Description
-------              ----                                ----------           -----------
0.0.58               Chocolatey                          PSGL                 This is an unofficial module with DSC resource to Install and configure Chocolatey.

PS C:\Windows\system32> Test-ChocolateyPackageIsInstalled -name EMCOPY64 -source ChocoGL -version latest

PackagePresent VersionGreaterOrEqual
-------------- ---------------------
         False                 False
raandree commented 4 years ago

Same error here, having a look into it.

@gaelcolas, do you still use these resources or would you recommend another DSC resource for Chocolatey?

raandree commented 4 years ago

Found something. These two environment variables were missing in my case:

PS C:\> dir env:choco*

Name                           Value
----                           -----
ChocolateyInstall              C:\ProgramData\chocolatey
ChocolateyLastPathUpdate       132270085137136849

I have installed Chocolatey and did not restart the machine. After the restart, everything worked as expected.

gaelcolas commented 4 years ago

I do but might be pinned to a former version.

The resource will probably be moved to the chocolatey organisation as soon as I get a chance (maybe Wednesday).

gaelcolas commented 1 year ago

ok so I've changed the way the module works (loads the Path variable from machine to $env:Path upon loading the module, and rewrote the resource to class-based. That should be fixed, closing.