Edit

Start a process

Description

This example shows how you can use the WindowsProcess resource to ensure a process is running.

Important

The PSDscResources module isn't supported. It won't receive any updates, including security fixes.

The module was archived on June 13, 2024. The last release was version 2.12.0.0 on June 26, 2019.

The documentation on this page reflects the last release of the PSDscResources module.

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'
        }
    }
}