microsoft / winget-cli

WinGet is the Windows Package Manager. This project includes a CLI (Command Line Interface), PowerShell modules, and a COM (Component Object Model) API (Application Programming Interface).
https://learn.microsoft.com/windows/package-manager/
MIT License
22.96k stars 1.43k forks source link

Machine Configuration and Software Package #4222

Open psinnathurai opened 6 months ago

psinnathurai commented 6 months ago

Brief description of your issue

I have a created a Machine Configuration Policy using the PowerShell DSC Module Microsoft.WinGet.DSC and deployed it to an Azure Arc Enabled Server with the Windows Server Insider Version 26063 which has winget installed. I receive the following Issue "PowerShell DSC resource Microsoft.WinGet.DSC failed to execute Set functionality with error message: WinGetPackage Failed installing Microsoft.PowerShell. InstallStatus 'NoApplicableInstallers' InstallerErrorCode '0' ExtendedError '-1978335216' The SendConfigurationApply function did not succeed. LCM failed to start desired state configuration manually."

Steps to reproduce

  1. Onboard a Windows Server Insider 26063 to Azure Arc
  2. Create a DSC File and convert it to a Machine Configuration using the following COmmands: `Configuration PowerShell7

    
    {
    Import-DscResource -ModuleName Microsoft.WinGet.DSC
    
    node localhost
    {
        WinGetPackage PowerShell7
        {
            Id = 'Microsoft.PowerShell'
            source = 'winget'
            InstallMode = 'silent'
        }
    }
    }

PowerShell7

New-GuestConfigurationPackage -Configuration powershell7\localhost.mof -Name WinGet_PowerShell7 -Type AuditAndSet

$existingAccountParams = @{ ResourceGroupname = 'rg-machineconfiguration-mgt-dev-szn-01' Name = 'stsimgtdevsznmachineconf' }

$container = Get-AzStorageAccount @existingAccountParams | Get-AzStorageContainer -Name machineconfiguration

$setParams = @{ Container = 'machineconfiguration' File = '.\WinGet_PowerShell7.zip' Context = $container.Context }

$blob = Set-AzStorageBlobContent @setParams $contentUri = $blob.ICloudBlob.Uri.AbsoluteUri

$PolicyConfig = @{ PolicyId = (New-Guid) ContentUri = $contentUri DisplayName = 'WinGet_PowerShell7' Description = 'Install PowerShell 7 using WinGet' Path = './WinGet_PowerShell7' Platform = 'Windows' PolicyVersion = '1.0.0' Mode = 'ApplyAndAutoCorrect' }

New-GuestConfigurationPolicy @PolicyConfig

New-AzPolicyDefinition -Name 'Winget_PowerShell7' -Policy

```WinGet_PowerShell7\WinGet_PowerShell7_DeployIfNotExists.json```
`

### Expected behavior

Expected behavior that it would install the defined Package on the Azure Arc Enabled Server.

### Actual behavior

![image](https://github.com/microsoft/winget-cli/assets/78587668/1132d109-be95-4174-9eba-c431f06b29a3)

The Policy appears multiple Times

### Environment

```shell
Windows: Windows.Server v10.0.26063.1
Systemarchitektur: X64
Paket: Microsoft.DesktopAppInstaller v1.22.10582.0

WinGet-Verzeichnisse
-----------------------------------------------------------------------------------------------------------------------
Protokolle                                   %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\Local…
Benutzereinstellungen                        %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\Local…
Verzeichnis für portierbare Links (Benutzer) %LOCALAPPDATA%\Microsoft\WinGet\Links
Portables Linkverzeichnis (Computer)         C:\Program Files\WinGet\Links
Portierbarer Paketstamm (Benutzer)           %LOCALAPPDATA%\Microsoft\WinGet\Packages
Portierbarer Paketstamm                      C:\Program Files\WinGet\Packages
Portierbares Paketstamm (x86)                C:\Program Files (x86)\WinGet\Packages
Installationsprogrammdownloads               %USERPROFILE%\Downloads

Links
-----------------------------------------------------------------------------------------
Datenschutzerklärung              https://aka.ms/winget-privacy
Lizenzvereinbarung                https://aka.ms/winget-license
Hinweise von Drittanbietern       https://aka.ms/winget-3rdPartyNotice
Startseite                        https://aka.ms/winget
Windows Store-Nutzungsbedingungen https://www.microsoft.com/en-us/storedocs/terms-of-sale

Administratoreinstellung                  Status
-----------------------------------------------------
LocalManifestFiles                        Deaktiviert
BypassCertificatePinningForMicrosoftStore Deaktiviert
InstallerHashOverride                     Deaktiviert
LocalArchiveMalwareScanOverride           Deaktiviert

Edited by @denelon to add formatting in markdown.

stephengillie commented 6 months ago

It seems like some of the formatting got lost in the posting process.

Configuration PowerShell7 {
    Import-DscResource -ModuleName Microsoft.WinGet.DSC
    node localhost {
        WinGetPackage PowerShell7 {
            Id = 'Microsoft.PowerShell'
            source = 'winget'
            InstallMode = 'silent'
        }
    }
}

PowerShell7

New-GuestConfigurationPackage -Configuration powershell7\localhost.mof -Name WinGet_PowerShell7 -Type AuditAndSet

$existingAccountParams = @{
    ResourceGroupname = 'rg-machineconfiguration-mgt-dev-szn-01'
    Name = 'stsimgtdevsznmachineconf'
}

$container = Get-AzStorageAccount @existingAccountParams |
Get-AzStorageContainer -Name machineconfiguration

$setParams = @{
    Container = 'machineconfiguration'
    File = '.\WinGet_PowerShell7.zip'
    Context = $container.Context
}

$blob = Set-AzStorageBlobContent @setParams
$contentUri = $blob.ICloudBlob.Uri.AbsoluteUri

$PolicyConfig = @{
    PolicyId = (New-Guid)
    ContentUri = $contentUri
    DisplayName = 'WinGet_PowerShell7'
    Description = 'Install PowerShell 7 using WinGet'
    Path = './WinGet_PowerShell7'
    Platform = 'Windows'
    PolicyVersion = '1.0.0'
    Mode = 'ApplyAndAutoCorrect'
}

New-GuestConfigurationPolicy @PolicyConfig

New-AzPolicyDefinition -Name 'Winget_PowerShell7' -Policy WinGet_PowerShell7\WinGet_PowerShell7_DeployIfNotExists.json
stephengillie commented 6 months ago

Hi @psinnathurai,

Thanks for the very detailed error report.

So this could be a scope mismatch if installed in User scope, or in a non-elevated session.

janegilring commented 6 months ago

@psinnathurai Does it work if you test applying the Machine Configuration package using Start-GuestConfigurationPackageRemediation -Path ".\WinGet_PowerShell7.zip" ?

Reason for asking is that Machine Configuration applies configurations as SYSTEM, so was wondering whether it behaves differently when applying the configuration as a regular (admin) user account.

stephengillie commented 6 months ago

Being in SYSTEM context might complicate the situation. The client only recently gained the ability to run in this context:

Hello all, we've published Microsoft.WinGet.Client with the ability to run WinGet in the system context. It does require running in PowerShell 7 with "-MTA".

Edit: And would require as prerequisite the same Powershell 7 package as this Issue was opened to install. Bit of a catch.

psinnathurai commented 6 months ago

Hi @psinnathurai,

Thanks for the very detailed error report.

  • From the error "NoApplicableInstallers", it sounds like a package manager level error - as though the package manager is successfully being interacted with and emitting an error.
  • From here, it could be a manifest issue. Reviewing the most recent Microsoft.Powershell installer file, all installers are set to Machine scope.

So this could be a scope mismatch if installed in User scope, or in a non-elevated session.

  • Is this running in an Administrator session or a non-elevated session?
  • Can the WinGet logs for the install be uploaded?
  • Have you tried installing any other software packages in this way?

How can I set the Machine Scope for the DSC Resource? I didn't found a Scope Property in the DSC Resources.

image

Machine Configuration should run in SYSTEM Context.

I also tried to install Visual Studio Code in the same Method now, with Visual Studio Code the Machine Configuration appears as Compliant even if Visual Studio code is not installed.

psinnathurai commented 6 months ago

@psinnathurai Does it work if you test applying the Machine Configuration package using Start-GuestConfigurationPackageRemediation -Path ".\WinGet_PowerShell7.zip" ?

Reason for asking is that Machine Configuration applies configurations as SYSTEM, so was wondering whether it behaves differently when applying the configuration as a regular (admin) user account.

I was able to run it in a Elevated Session but I needed to install PowerShell 7 first.. So to install PowerShell 7 using Winget a Prereq would be PowerShell 7 itself?

I tried to install Visual Studio Code now.

image

image

denelon commented 6 months ago

The WinGet DSC Resource depends on the Microsoft.WinGet.Client PowerShell module for most operations. We still have work to see if we can get it to work correctly using Windows PowerShell. There are several missing dependencies we're working to identify and include in the module. For now, you would need PowerShell 7 to run cmdlets like "Install-WinGetPackage".

Note: Repair-WinGetPackageManager should work in Windows PowerShell.