Megosztás a következőn keresztül:


Folyamat indítása

Description

Ez a példa bemutatja, hogyan használhatja az WindowsProcess erőforrást egy folyamat futásának biztosítására.

Ha a PresentBiztos beállítás értéke, az C:\Windows\System32\gpresult.exeElérési út és az Argumentumok beállítás értéke/h C:\gp2.htm, akkor az erőforrás a megadott argumentumokkal kezdődikgpresult.exe, ha nem fut.

A Invoke-DscResource

Ez a szkript bemutatja, hogyan használhatja az WindowsProcess erőforrást a Invoke-DscResource parancsmaggal annak ellenőrzésére gpresult.exe , hogy az argumentumokkal /h C:\gp2.htmfut-e.

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

Konfigurációval

Ez a kódrészlet bemutatja, hogyan definiálhat egy Configuration erőforrásblokkot WindowsProcess , hogy meggyőződjön arról gpresult.exe , hogy az argumentumokkal /h C:\gp2.htmfut.

Configuration Start {
    Import-DSCResource -ModuleName 'PSDscResources'

    Node localhost {
        WindowsProcess ExampleWindowsProcess {
            Path      = 'C:\Windows\System32\gpresult.exe'
            Arguments = '/h C:\gp2.htm'
            Ensure    = 'Present'
        }
    }
}