说明
此示例演示如何使用 WindowsFeatureSet
复合资源来确保随子功能一起安装多个 Windows 功能。
如果“确保”设置为Absent
“和”名称“设置为数组,Telnet-Client
RSAT-File-Services
则资源会卸载Telnet-Client
和 RSAT-File-Services
Windows 功能及其子功能(如果已安装)。
将 LogPath 设置为 C:\LogPath\Log.log
时,如果资源需要卸载 Telnet-Client
, RSAT-File-Services
或者资源会将卸载日志写入其中 C:\LogPath\Log.log
。
使用 Invoke-DscResource
该 Invoke-DscResource
cmdlet 不支持调用复合资源。 请改用 WindowsFeature 资源。
使用配置
此代码片段演示如何使用资源块定义,Configuration
WindowsFeatureSet
以确保Telnet-Client
卸载 Windows RSAT-File-Services
功能和子功能。
重要
计算机配置存在限制,阻止 DSC 资源使用 PowerShell 本身中不包含的任何 PowerShell cmdlet 或Galeria programu PowerShell上的模块。 此示例出于演示目的提供,但由于 DSC 资源使用 DISM 模块中的 cmdlet(作为 Windows 模块之一提供),因此它在计算机配置中不起作用。
Configuration Uninstall {
Import-DscResource -ModuleName 'PSDscResources'
Node localhost {
WindowsFeatureSet ExampleWindowsFeatureSet {
Name = @(
'Telnet-Client'
'RSAT-File-Services'
)
Ensure = 'Absent'
LogPath = 'C:\LogPath\Log.log'
}
}
}