Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Description
This example shows how you can use the WindowsProcess resource to ensure a process is running.
With Ensure set to Present, Path set to C:\Windows\System32\gpresult.exe, and
Arguments set to /h C:\gp2.htm, the resource starts gpresult.exe with the specified
arguments if it isn't running.
With Invoke-DscResource
This script shows how you can use the WindowsProcess resource with the Invoke-DscResource cmdlet
to ensure gpresult.exe is running with the arguments /h C:\gp2.htm.
[CmdletBinding()]
param()
begin {
    $SharedParameters = @{
        Name       = 'WindowsProcess'
        ModuleName = 'PSDscResource'
        Properties = @{
            Path      = 'C:\Windows\System32\gpresult.exe'
            Arguments = '/h C:\gp2.htm'
            Ensure    = 'Present'
        }
    }
    $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
    }
}
With a Configuration
This snippet shows how you can define a Configuration with a WindowsProcess resource block to
ensure gpresult.exe is running with the arguments /h C:\gp2.htm.
Configuration Start {
    Import-DSCResource -ModuleName 'PSDscResources'
    Node localhost {
        WindowsProcess ExampleWindowsProcess {
            Path      = 'C:\Windows\System32\gpresult.exe'
            Arguments = '/h C:\gp2.htm'
            Ensure    = 'Present'
        }
    }
}