説明
この例では、リソースを使用 WindowsProcess してプロセスが実行されていないことを確認する方法を示します。
[確認] を [パス] にC:\Windows\System32\gpresult.exeAbsent設定し、引数を空の文字列に設定すると、リソースは実行中gpresult.exeのプロセスを停止します。
Invoke-DscResource
このスクリプトは、コマンドレットでリソースを WindowsProcess 使用して実行されていないことを Invoke-DscResource 確認 gpresult.exe する方法を示しています。
[CmdletBinding()]
param()
begin {
$SharedParameters = @{
Name = 'WindowsFeatureSet'
ModuleName = 'PSDscResource'
Properties = @{
Path = 'C:\Windows\System32\gpresult.exe'
Arguments = ''
Ensure = 'Absent'
}
}
$NonGetProperties = @(
'Ensure'
)
}
process {
$TestResult = Invoke-DscResource -Method Test @SharedParameters
if ($TestResult.InDesiredState) {
$QueryParameters = $SharedParameters.Clone()
foreach ($Property in $NonGetProperties) {
$QueryParameters.Properties.Remove($Property)
}
Invoke-DscResource -Method Get @QueryParameters
} else {
Invoke-DscResource -Method Set @SharedParameters
}
}
構成を使用する
このスニペットは、リソース ブロックを Configuration 使用 WindowsProcess して定義して、実行されていないことを確認 gpresult.exe する方法を示しています。
Configuration Stop {
Import-DSCResource -ModuleName 'PSDscResources'
Node localhost {
WindowsProcess ExampleWindowsProcess {
Path = 'C:\Windows\System32\gpresult.exe'
Arguments = ''
Ensure = 'Absent'
}
}
}
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。