Invoke-DscResource 
	运行指定的 PowerShell Desired State Configuration (DSC) 资源的方法。
语法
Default (默认值)
Invoke-DscResource
    [-Name] <String>
    [[-ModuleName] <ModuleSpecification>]
    [-Method] <String>
    [-Property] <Hashtable>
    [<CommonParameters>]
说明
              Invoke-DscResource cmdlet 运行指定的 PowerShell Desired State Configuration (DSC) 资源的方法。
此 cmdlet 直接调用 DSC 资源,而无需创建配置文档。 使用此 cmdlet,配置管理产品可以使用 DSC 资源管理 Windows 或 Linux。
此 cmdlet 不适用于复合资源。 复合资源是参数化配置。 使用复合资源需要 LCM。
示例
示例 1:通过指定资源的必需属性调用 Set 方法
此示例调用名为 WindowsProcess 的资源的 Set 方法,并提供必需的 路径 和 参数 属性来启动指定的 Windows 进程。
Invoke-DscResource -Name WindowsProcess -Method Set -ModuleName PSDesiredStateConfiguration -Property @{
    Path      = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe'
    Arguments = ''
}
示例 2:为指定的模块调用资源的 Test 方法
此示例调用名为 WindowsProcess的资源的 Test 方法,该方法位于名为 PSDesiredStateConfiguration的模块中。
$SplatParam = @{
    Name       = 'WindowsProcess'
    ModuleName = 'PSDesiredStateConfiguration'
    Method     = 'Test'
    Property   = @{
        Path      = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe'
        Arguments = ''
    }
}
Invoke-DscResource @SplatParam
参数
-Method
指定此 cmdlet 调用的资源的方法。 此参数的可接受值为:Get、Set和 Test。
参数属性
| 类型: | String | 
| 默认值: | None | 
| 接受的值: | Get, Set, Test | 
| 支持通配符: | False | 
| 不显示: | False | 
参数集
(All)
| Position: | 2 | 
| 必需: | True | 
| 来自管道的值: | False | 
| 来自管道的值(按属性名称): | False | 
| 来自剩余参数的值: | False | 
-ModuleName 
		指定要调用的指定 DSC 资源模块的名称。
参数属性
| 类型: | ModuleSpecification | 
| 默认值: | None | 
| 支持通配符: | False | 
| 不显示: | False | 
参数集
(All)
| Position: | 1 | 
| 必需: | False | 
| 来自管道的值: | True | 
| 来自管道的值(按属性名称): | True | 
| 来自剩余参数的值: | False | 
-Name
指定要调用的 DSC 资源的名称。
参数属性
| 类型: | String | 
| 默认值: | None | 
| 支持通配符: | False | 
| 不显示: | False | 
参数集
(All)
| Position: | 0 | 
| 必需: | True | 
| 来自管道的值: | True | 
| 来自管道的值(按属性名称): | True | 
| 来自剩余参数的值: | False | 
-Property
将哈希表中的资源属性名称和值分别指定为键和值。
参数属性
| 类型: | Hashtable | 
| 默认值: | None | 
| 支持通配符: | False | 
| 不显示: | False | 
参数集
(All)
| Position: | 3 | 
| 必需: | True | 
| 来自管道的值: | False | 
| 来自管道的值(按属性名称): | False | 
| 来自剩余参数的值: | False | 
CommonParameters
此 cmdlet 支持通用参数:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 有关详细信息,请参阅 about_CommonParameters。
输入
String
ModuleSpecification
输出
Object
备注
- 在 Windows PowerShell 5.1 资源中,除非使用密钥 PsDscRunAsCredential使用用户上下文指定,否则在系统上下文下运行。 在 PowerShell 7.0 中,资源在用户的上下文中运行,并且不再支持 PsDscRunAsCredential。 使用此密钥会导致 cmdlet 引发异常。 
- 从 PowerShell 7 起, - Invoke-DscResource不再支持调用 WMI DSC 资源。 这包括 PSDesiredStateConfiguration中的 文件 和 日志 资源。