PowerShell / PSDscResources

MIT License
129 stars 54 forks source link

WindowsFeature: Resource thinks Windows Server 2022 Azure Edition Core is a Client OS #208

Open ricohomewood opened 2 years ago

ricohomewood commented 2 years ago

Details of the scenario you tried and the problem that is occurring

When using the new Guest Configuration feature in Azure Guest Configuration to apply DSC config via Azure Policy. I am getting an error when trying to configure a Windows Feature on Windows Server 2022 Azure Edition Core see below

That may not be related to the fact i'm using Guest Configuration but note GuestConfiguration uses Powershell 7.

The VM SKU is:

"publisher": "MicrosoftWindowsServer",
"offer": "WindowsServer",
"sku": "2022-datacenter-azure-edition-core",
"version": "latest"

Verbose logs showing the problem

PowerShell DSC resource MSFT_WindowsFeature  failed to execute Test-TargetResource functionality with error message: System.InvalidOperationException: Installing roles and features using PowerShell Desired State Configuration is supported only on Server SKU's. It is not supported on Client SKU. 

Suggested solution to the issue

The DSC configuration that is used to reproduce the issue (as detailed as possible)

Configuration ConfigureAndDeployWebFarm
{

    Import-DSCResource -ModuleName NetworkingDSC
    Import-DSCResource -ModuleName PSDscResources
    Import-DscResource -ModuleName xWebAdministration

    Node localhost
    {
       WindowsFeature webServer
        {
            Ensure = 'Present'
            Name = 'Web-Server'
        }
    }
}

The operating system the target node is running

OsName               : Microsoft Windows Server 2022 Datacenter Azure Edition
OsOperatingSystemSKU : 407
OsArchitecture       : 64-bit
WindowsVersion       : 2009
WindowsBuildLabEx    : 20348.859.amd64fre.fe_release_svc_prod2.220707-1832
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

Version and build of PowerShell the target node is running

PS Version (bundled with Guest Configuration)

Name                           Value
----                           -----
PSVersion                      7.1.2
PSEdition                      Core
GitCommitId                    7.1.2
OS                             Microsoft Windows 10.0.20348
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version of the DSC module that was used ('dev' if using current dev branch)

2.12.0.0 PSDscResources

chadlindell commented 2 years ago

The PSDscResources WindowsFeature resource does not work as a guest configuration on any version of Windows, server or not, because it needs the ServerManager module. The built-in Windows PowerShell module ServerManager is .Net based. When you run normal PS7 it can make use of this module and its commands through its compatibility features. However, a guest configuration task runs in an isolated instance of PS7 that can't touch these modules (at least I haven't found a way). Nobody has migrated ServerManager to be .Net Core based so it can work natively in PS7, or least I haven't seen yet.

Edit: A solution.

MS gives the answer on how to mitigate this issue, by modifying the PowerShell Core PSModulePath at runtime to allow PS Core to see the Windows modules.

https://learn.microsoft.com/en-us/azure/governance/machine-configuration/machine-configuration-custom#running-commands-in-windows-powershell