إيقاف عملية

الوصف

يوضح هذا المثال كيف يمكنك استخدام WindowsProcess المورد لضمان عدم تشغيل عملية.

مع تعيين Ensure إلى Absent، وتعيين المسار إلى C:\Windows\System32\gpresult.exe، وتعيين الوسيطات إلى سلسلة فارغة، يوقف المورد أي عملية قيد التشغيل gpresult.exe .

مع Invoke-DscResource

يوضح هذا البرنامج النصي كيف يمكنك استخدام WindowsProcess المورد مع Invoke-DscResource cmdlet للتأكد من 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'
        }
    }
}