Invoke-DscResource
Runs a method of a specified PowerShell Desired State Configuration (DSC) resource.
Sintaxe
Default (Predefinição)
Invoke-DscResource
[-Name] <String>
[[-ModuleName] <ModuleSpecification>]
[-Method] <String>
[-Property] <Hashtable>
[<CommonParameters>]
Description
The Invoke-DscResource
cmdlet runs a method of a specified PowerShell Desired State Configuration
(DSC) resource.
This cmdlet invokes a DSC resource directly, without creating a configuration document. Using this cmdlet, configuration management products can manage windows or Linux with DSC resources.
This cmdlet doesn't work with composite resources. Composite resources are parameterized configurations. Using composite resources requires the LCM.
Note
Before PSDesiredStateConfiguration 2.0.6, using Invoke-DscResource
in PowerShell 7 requires
enabling a PowerShell experimental feature. To use the cmdlet in versions 2.0.0 through 2.0.5,
you must enable it with the following command.
Enable-ExperimentalFeature PSDesiredStateConfiguration.InvokeDscResource
Exemplos
Example 1: Invoke the Set method of a resource by specifying its mandatory properties
This example invokes the Set method of a resource named WindowsProcess and provides the mandatory Path and Arguments properties to start the specified Windows process.
Invoke-DscResource -Name WindowsProcess -Method Set -ModuleName PSDesiredStateConfiguration -Property @{
Path = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe'
Arguments = ''
}
Example 2: Invoke the Test method of a resource for a specified module
This example invokes the Test method of a resource named WindowsProcess, which is in the module named PSDesiredStateConfiguration.
$SplatParam = @{
Name = 'WindowsProcess'
ModuleName = 'PSDesiredStateConfiguration'
Method = 'Test'
Property = @{
Path = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe'
Arguments = ''
}
}
Invoke-DscResource @SplatParam
Parâmetros
-Method
Specifies the method of the resource that this cmdlet invokes. The acceptable values for this parameter are: Get, Set, and Test.
Propriedades dos parâmetros
Tipo: | String |
Default value: | None |
Valores aceites: | Get, Set, Test |
Suporta carateres universais: | False |
NãoMostrar: | False |
Conjuntos de parâmetros
(All)
Position: | 2 |
Obrigatório: | True |
Valor do pipeline: | False |
Valor do pipeline por nome de propriedade: | False |
Valor dos restantes argumentos: | False |
-ModuleName
Specifies the name of the module providing the specified DSC Resource to invoke.
Propriedades dos parâmetros
Tipo: | ModuleSpecification |
Default value: | None |
Suporta carateres universais: | False |
NãoMostrar: | False |
Conjuntos de parâmetros
(All)
Position: | 1 |
Obrigatório: | False |
Valor do pipeline: | True |
Valor do pipeline por nome de propriedade: | True |
Valor dos restantes argumentos: | False |
-Name
Specifies the name of the DSC resource to invoke.
Propriedades dos parâmetros
Tipo: | String |
Default value: | None |
Suporta carateres universais: | False |
NãoMostrar: | False |
Conjuntos de parâmetros
(All)
Position: | 0 |
Obrigatório: | True |
Valor do pipeline: | True |
Valor do pipeline por nome de propriedade: | True |
Valor dos restantes argumentos: | False |
-Property
Specifies the resource property name and its value in a hash table as key and value, respectively.
Propriedades dos parâmetros
Tipo: | Hashtable |
Default value: | None |
Suporta carateres universais: | False |
NãoMostrar: | False |
Conjuntos de parâmetros
(All)
Position: | 3 |
Obrigatório: | True |
Valor do pipeline: | False |
Valor do pipeline por nome de propriedade: | False |
Valor dos restantes argumentos: | False |
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
Entradas
Saídas
Notas
In Windows PowerShell 5.1 resources ran under the System context unless specified with user context using the key PsDscRunAsCredential. In PowerShell 7.0, Resources run in the user's context, and PsDscRunAsCredential is no longer supported. Using this key causes the cmdlet to throw an exception.
As of PowerShell 7,
Invoke-DscResource
no longer supports invoking WMI DSC resources. This includes the File and Log resources in PSDesiredStateConfiguration.