PowerShell / PackageManagementProviderResource

Modules with DSC resources for the PackageManagement(aka OneGet) providers.
MIT License
37 stars 24 forks source link

Unable to find package source 'PSGallery' #43

Open VerdonTrigance opened 4 years ago

VerdonTrigance commented 4 years ago
Configuration PSModulesConfig
{
    Import-DscResource -ModuleName 'PSDesiredStateConfiguration'    
    Import-DscResource -ModuleName @{ModuleName="PackageManagement"; RequiredVersion="1.4.7"}

    Node $AllNodes.NodeName {
        foreach ($moduleName in $Node.Modules) {        
            PackageManagement $moduleName {             
                Name = $moduleName
                Source = "PSGallery"
                Ensure = "Present"
            }
        }
    }
}
PSModulesConfig -OutputPath $OutputPath -ConfigurationData "$PSScriptRoot\ConfigurationData.psd1"

generates mof files, but:

Start-DscConfiguration c:\dsc\modules -Wait -force -Verbose -ComputerName dev-02

VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer dev-04 with user sid S-1-5-21-845132264-889049626-1544394932-198784.
VERBOSE: [dev-02]: LCM:  [ Start  Set      ]
VERBOSE: [dev-02]: LCM:  [ Start  Resource ]  [[PackageManagement]SqlServer]
VERBOSE: [dev-02]: LCM:  [ Start  Test     ]  [[PackageManagement]SqlServer]
VERBOSE: [dev-02]:                            [[PackageManagement]SqlServer] Test-TargetResource calling Get-TargetResource using -Name SqlServer -Source PSGallery -Ensure Present -Verbose True .
VERBOSE: [dev-02]:                            [[PackageManagement]SqlServer] Begin invoking Get-package -Name SqlServer -Verbose True  using PSModulePath C:\Windows\system32\config\systemprofile\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules;c:\Program Files\AppFabric 1.1 for Windows Server\PowershellModules.
VERBOSE: [dev-02]:                            [[PackageManagement]SqlServer] Acquiring providers for assembly: C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.4.7\fullclr\Microsoft.PackageManagement.MsuProvider.dll
VERBOSE: [dev-02]:                            [[PackageManagement]SqlServer] Acquiring providers for assembly: C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.4.7\fullclr\Microsoft.PackageManagement.MetaProvider.PowerShell.dll
VERBOSE: [dev-02]:                            [[PackageManagement]SqlServer] Acquiring providers for assembly: C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.4.7\fullclr\Microsoft.PackageManagement.MsiProvider.dll
VERBOSE: [dev-02]:                            [[PackageManagement]SqlServer] Acquiring providers for assembly: C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.4.7\fullclr\Microsoft.PackageManagement.ArchiverProviders.dll
VERBOSE: [dev-02]:                            [[PackageManagement]SqlServer] Acquiring providers for assembly: C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.4.7\fullclr\Microsoft.PackageManagement.NuGetProvider.dll
VERBOSE: [dev-02]:                            [[PackageManagement]SqlServer] Acquiring providers for assembly: C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.4.7\fullclr\Microsoft.PackageManagement.CoreProviders.dll
VERBOSE: [dev-02]:                            [[PackageManagement]SqlServer] Cannot download link 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409', retrying for '2' more times.
VERBOSE: [dev-02]:                            [[PackageManagement]SqlServer] Cannot download link 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409', retrying for '1' more times.
VERBOSE: [dev-02]:                            [[PackageManagement]SqlServer] Cannot download link 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409', retrying for '0' more times.
VERBOSE: [dev-02]:                            [[PackageManagement]SqlServer] **Package 'SqlServer' not found.**
VERBOSE: [dev-02]:                            [[PackageManagement]SqlServer] Resource SqlServer is not in the desired state. Required Ensure is Present and actual Ensure is Absent
VERBOSE: [dev-02]: LCM:  [ End    Test     ]  [[PackageManagement]SqlServer]  in 6.0160 seconds.
VERBOSE: [dev-02]: LCM:  [ Start  Set      ]  [[PackageManagement]SqlServer]
VERBOSE: [dev-02]:                            [[PackageManagement]SqlServer] Set-TargetResource calling Test-TargetResource using -Name SqlServer -Source PSGallery -Ensure Present -Verbose True .
VERBOSE: [dev-02]: LCM:  [ End    Set      ]  [[PackageManagement]SqlServer]  in 0.4840 seconds.
**PowerShell DSC resource MSFT_PackageManagement  failed to execute Set-TargetResource functionality with error message: The running command stopped because the preference variable "ErrorActionPreference" or common 
parameter is set to Stop: Unable to find package source 'PSGallery'. Use Get-PackageSource to see all available package sources.** 
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : ProviderOperationExecutionFailure
    + PSComputerName        : dev-02

VERBOSE: [dev-02]: LCM:  [ End    Set      ]
The SendConfigurationApply function did not succeed.
    + CategoryInfo          : NotSpecified: (root/Microsoft/...gurationManager:String) [], CimException
    + FullyQualifiedErrorId : MI RESULT 1
    + PSComputerName        : dev-02

VERBOSE: Operation 'Invoke CimMethod' complete.
VERBOSE: Time taken for configuration job to complete is 9.685 seconds

But it is here:

PS C:\Windows\system32> get-packageSource

Name                             ProviderName     IsTrusted  Location                                                                                                                      
----                             ------------     ---------  --------                                                                                                                      
nuget.org                        NuGet            False      https://api.nuget.org/v3/index.json                                                                                           
PSGallery                        PowerShellGet    True       https://www.powershellgallery.com/api/v2                                                                                      

Command 'get-packageSource' was executed from my current account, but DSC runs from SYSTEM. Ok. Try to register PackageSource for SYSTEM:

Configuration PSModulesConfig
{
    Import-DscResource -ModuleName 'PSDesiredStateConfiguration'    
    Import-DscResource -ModuleName @{ModuleName="PackageManagement"; RequiredVersion="1.4.7"}

    Node $AllNodes.NodeName {
        PackageManagementSource PSGallery
        {
            Ensure = "Present"
            Name = "PSGallery"
            ProviderName = "PowerShellGet"
            SourceLocation = "https://www.powershellgallery.com/api/v2"
            InstallationPolicy = "Trusted"
        }

        foreach ($moduleName in $Node.Modules) {        
            PackageManagement $moduleName {             
                Name = $moduleName
                Source = "PSGallery"
                Ensure = "Present"
            }
        }
    }
}
PSModulesConfig -OutputPath $OutputPath -ConfigurationData "$PSScriptRoot\ConfigurationData.psd1"

Shows me that over and over again:

VERBOSE: [dev-02]: LCM:  [ Start  Set      ]
VERBOSE: [dev-02]: LCM:  [ Start  Resource ]  [[PackageManagementSource]PSGallery]
VERBOSE: [dev-02]: LCM:  [ Start  Test     ]  [[PackageManagementSource]PSGallery]
VERBOSE: [dev-02]:                            [[PackageManagementSource]PSGallery] Begin invoking Get-packageSource PSGallery
VERBOSE: [dev-02]:                            [[PackageManagementSource]PSGallery] Acquiring providers for assembly: C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.4.7\fullclr\Microsoft.PackageManagement.MetaProvider.PowerShell.dll
VERBOSE: [dev-02]:                            [[PackageManagementSource]PSGallery] Acquiring providers for assembly: C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.4.7\fullclr\Microsoft.PackageManagement.ArchiverProviders.dll
VERBOSE: [dev-02]:                            [[PackageManagementSource]PSGallery] Acquiring providers for assembly: C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.4.7\fullclr\Microsoft.PackageManagement.MsiProvider.dll
VERBOSE: [dev-02]:                            [[PackageManagementSource]PSGallery] Acquiring providers for assembly: C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.4.7\fullclr\Microsoft.PackageManagement.NuGetProvider.dll
VERBOSE: [dev-02]:                            [[PackageManagementSource]PSGallery] Acquiring providers for assembly: C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.4.7\fullclr\Microsoft.PackageManagement.CoreProviders.dll
VERBOSE: [dev-02]:                            [[PackageManagementSource]PSGallery] Acquiring providers for assembly: C:\Program Files\WindowsPowerShell\Modules\PackageManagement\1.4.7\fullclr\Microsoft.PackageManagement.MsuProvider.dll
VERBOSE: [dev-02]:                            [[PackageManagementSource]PSGallery] Cannot download link 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409', retrying for '2' more times.
VERBOSE: [dev-02]:                            [[PackageManagementSource]PSGallery] Cannot download link 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409', retrying for '1' more times.
VERBOSE: [dev-02]:                            [[PackageManagementSource]PSGallery] Cannot download link 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409', retrying for '0' more times.
VERBOSE: [dev-02]:                            [[PackageManagementSource]PSGallery] **Package source 'PSGallery' not found**
VERBOSE: [dev-02]:                            [[PackageManagementSource]PSGallery] Resource PSGallery is not in the desired state. Required Ensure is Present and actual Ensure is Absent
VERBOSE: [dev-02]: LCM:  [ End    Test     ]  [[PackageManagementSource]PSGallery]  in 4.8910 seconds.
VERBOSE: [dev-02]: LCM:  [ Start  Set      ]  [[PackageManagementSource]PSGallery]
WARNING: [dev-02]:                            [[PackageManagementSource]PSGallery] Begin registering 'PSGallery' to source location 'https://www.powershellgallery.com/api/v2' with 'Trusted' policy"
VERBOSE: [dev-02]:                            [[PackageManagementSource]PSGallery] Begin invoking Register-Packagesource PSGallery
VERBOSE: [dev-02]:                            [[PackageManagementSource]PSGallery] **Successfully registered the package source PSGallery**
VERBOSE: [dev-02]: LCM:  [ End    Set      ]  [[PackageManagementSource]PSGallery]  in 4.8120 seconds.
VERBOSE: [dev-02]: LCM:  [ End    Resource ]  [[PackageManagementSource]PSGallery]

Definitely it's not registered successfully.

At the end I tell my goal - install some modules through DSC automatically with Azure Agent. It means I can not use my own account, but only service account with AllowLogonLocally = false, following one additional limitation - I can not use PSDSCRunAsCredential with such account. So, it means I should install modules under the SYSTEM passing proxy to it. I had set up $PROFILE.AllUsersAllHosts with proxy, but guess it is not helping.