functions/Repair-DSCEngine.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function Repair-DSCEngine {
    [CmdletBinding()]
    param
    (
    [ValidateNotNullOrEmpty()]
    [string[]]$ComputerName
    )

    #kill the dsc processes on the remote system
    Invoke-Command -ComputerName $ComputerName -ScriptBlock {

        ### find the process that is hosting the DSC engine
        $dscProcess = Get-WmiObject msft_providers | 
        Where-Object {$_.provider -like 'dsccore'} | 
        Select-Object -ExpandProperty HostProcessIdentifier 

        ### Stop the process
        do {
            $processID = Get-Process -Id $dscProcess
            $processID | Stop-Process -Force}
        while ($processID.ProcessName -match "WmiPrvSE")
    } -ErrorAction SilentlyContinue
}