我一直在尝试在 Windows Server 2016 Nano (TP 5) 上运行 Powershell DSC。当我运行配置时,出现以下错误:
PowerShell DSC 资源 MSFT_xWindowsFeature 无法执行 Test-TargetResource 功能,并显示错误消息:使用 PowerShell 所需状态配置安装角色和功能仅在服务器 SKU 上受支持。客户端 SKU 不支持。
当然,Nano 是一个服务器 SKU,对吧?
如果你感兴趣的话,下面是我正在使用的 DSC 配置(尽管我确实需要修复一个问题,请参阅https://github.com/PowerShell/xPSDesiredStateConfiguration/pull/258):
Configuration Webserver
{
Import-DscResource -ModuleName xPSDesiredStateConfiguration
Node "172.28.128.9"
{
Log MyMessage
{
Message = "This installs IIS"
}
xWindowsFeature "Webserver"
{
Name = "Web-Server"
Ensure = "Present"
IncludeAllSubFeature = $TRUE
}
}
}
答案1
MSFT_xWindowsFeature.psm1 中的 Test-TargetResource 函数尝试导入服务器管理器 PS 模块(在纳米服务器中不可用),如果失败则抛出该异常:
try
{
Import-Module -Name 'ServerManager' -ErrorAction Stop
}
catch [System.Management.Automation.RuntimeException] {
if ($_.Exception.Message -like "*Some or all identity references could not be translated*")
{
Write-Verbose $_.Exception.Message
}
else
{
Write-Verbose -Message $script:localizedData.ServerManagerModuleNotFoundMessage
New-InvalidOperationException -Message $script:localizedData.SkuNotSupported
}
}
catch
{
Write-Verbose -Message $script:localizedData.ServerManagerModuleNotFoundMessage
New-InvalidOperationException -Message $script:localizedData.SkuNotSupported
}
该错误消息的文本不一定准确说明服务器是客户端 SKU,并且在 MSFT_xWindowsFeature.strings.psd1 中定义:
SkuNotSupported = Installing roles and features using PowerShell Desired State Configuration is supported only on Server SKU's. It is not supported on Client SKU.