Observe the following DSC configuration:
Configuration Example
{
Import-DscResource –ModuleName PSDesiredStateConfiguration
node localhost
{
WindowsFeature 'NetFramework45'
{
Name = 'NET-Framework-45-Core'
Ensure = 'Present'
}
}
}
It enables the .NET 4.5 on a Windows Server. But the WindowsFeature resource only works on server. Now, I would like to reach the same effect on a non server machine. What would be the right way to express it in PowerShell DSC?
The
WindowsFeature
DSC resource is based on theInstall-WindowsFeature
cmdlet, and is only available on Server.To enable features on Windows client (i.e. non-Server), you'll need to use the WindowsOptionalFeature resource, which works over DISM.
To enumerate a list of features on your particular version, you can use
Get-WindowsOptionalFeature -Online
or DISM from the command line:dism.exe /online /get-features
.You asked about
NET-Framework-45-Core
. This is not a separately installable/removable feature on Windows 10 client, for example.To identify the DISM features for any particular Windows Server feature, you can look at the results of
(Get-WindowsFeature <name>).AdditionalInfo.InstallName
. For example, the DISM feature forNET-Framework-45-Core
isNetFx4
.Note that while DISM.exe and
WindowsOptionalFeature
also work on Windows Server, it is not recommended as the relationships between features in Server is more complicated and those relationships are understood and managed by additional metadata exposed through the *-WindowsFeature cmdlets, as well as Server Manager and a WMI provider. Directly installing the discovered DISM features as described above will not necessarily install all needed or recommended additional components to make the feature work correctly.