2016년 2월 4일 목요일

SCCM - Uninstall of ConfigMgr 2012 client failed with error code 0x80070643

http://www.scconfigmgr.com/2015/02/11/uninstall-of-configmgr-2012-client-failed-with-error-code-0x80070643/

124_1
During a migration project with a customer, we ran into the problem where some of the clients wouldn’t be uninstalled correctly. When using the supported way of uninstalling the ConfigMgr 2012 client, the following error was shown in the ccmsetup.log file:
Installation failed with error code 1603
A Fallback Status Point has not been specified. Message with STATEID=’301′ will not be sent.
CcmSetup failed with error code 0x80070643
124_1
We tried rebooting the device that were failing, but as good of a troubleshooting tactic that might be for Windows systems, it didn’t work (who would’ve thought that anyway). When we interpreted the client.msi_uninstall.log file, that didn’t contain more than a few lines, we didn’t get that much more wiser. The only thing that we could get out of that log file was the following:
MainEngineThread is returning 1603
Well thank you very much for giving us that fatal error message all over again!
A quick search on Google pointed us in the direction where it could be related to a faulty WMI repository. We ran a few queries and for the most part it gave us an unexpected error. So we decided to try to rebuild the WMI repository on one of the devices that were experiencing problems when trying to uninstall the ConfigMgr client. At this point I realized that I’ve been wanting to write a PowerShell script that would assist in rebuilding the WMI repository, but I didn’t yet have had any time. After some digging around on the internet and a few rows of code, I ended up with the following code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<#
.SYNOPSIS
    Maintenance script for Windows Management Instrumentation
.DESCRIPTION
    This script can perform management tasks such as rebuilding the WMI repository. On Windows 6.x and above, the default behaviour of this script
    is to salvage the WMI repository first. If that doesn't give any successful results, you'll have the option add the Reset parameter
.PARAMETER Task
    Specify a maintenance task to perform
 
    Valid tasks:
    - Rebuild
.PARAMETER Reset
    Enables you to reset the WMI repository instead of the default option that is to salvage (only for Windows 6.x and above)
.EXAMPLE    
     .\Start-WMIMaintenance -Task Rebuild -Verbose    
     Rebuilds the WMI repository on the local system, showing verbose output
.NOTES    
     Script name: Start-WMIMaintenance.ps1    
     Version:     1.0    
     Author:      Nickolaj Andersen    
     Contact:     @NickolajA    
     DateCreated: 2015-02-11
#>
[CmdletBinding(SupportsShouldProcess=$true)]
param(
    [parameter(Mandatory=$true)]
    [ValidateSet("Rebuild")]
    [string]$Task,
    [parameter(Mandatory=$false)]
    [switch]$Reset
)
Begin {
    # Stop Windows Management Instrumentation dependent services
    $RunningServicesArrayList = New-Object -TypeName System.Collections.ArrayList
    foreach ($Service in (Get-Service -Name Winmgmt).DependentServices) {
        if ($Service.Status -like "Running") {
            $RunningServicesArrayList.Add($Service.Name) | Out-Null
            Write-Verbose -Message "Stopping Winmgmt dependent service '$($Service.Name)'"
            Stop-Service -Name $Service.Name -Force -ErrorAction Stop
        }
    }
    try {
    # Stop Windows Management Instrumentation service
        Write-Verbose -Message "Stopping Windows Management Instrumentation service"
        Stop-Service -Name "Winmgmt" -Force -ErrorAction Stop
    }
    catch {
        Throw "Unable to stop 'Winmgmt' service"
    }
 
    # Contruct an array of locations to the WMI repository
    $WMIPaths = @((Join-Path -Path $env:SystemRoot -ChildPath "System32\wbem"),(Join-Path -Path $env:SystemRoot -ChildPath "SysWOW64\wbem"))
}
Process {
    if ($PSBoundParameters.Values -contains "Rebuild") {
        # Re-register WMI executables
        foreach ($WMIPath in $WMIPaths) {
            if (Test-Path -Path $WMIPath -PathType Container) {
                $WMIExecutables = @("unsecapp.exe","wmiadap.exe","wmiapsrv.exe","wmiprvse.exe","scrcons.exe")
                foreach ($WMIExecutable in $WMIExecutables) {
                    $CurrentExecutablePath = (Join-Path -Path $WMIPath -ChildPath $WMIExecutable)
                    if (Test-Path -Path $CurrentExecutablePath -PathType Leaf) {
                        Write-Verbose -Message "Registering: $($CurrentExecutablePath)"
                        Start-Process -FilePath $CurrentExecutablePath -ArgumentList "/RegServer" -Wait
                    }
                }
            }
            else {
                Write-Warning -Message "Unable to locate path '$($WMIPath)'"
            }
        }
 
        # Reset WMI repository
        if ([System.Environment]::OSVersion.Version.Major -ge 6) {
            $WinMgmtPath = Join-Path -Path $env:SystemRoot -ChildPath "\System32\wbem\winmgmt.exe"
            if ($PSBoundParameters["Reset"]) {
                Write-Verbose -Message "Resetting WMI repository"
                Start-Process -FilePath $WinMgmtPath -ArgumentList "/resetrepository" -Wait
            }
            else {
                Write-Verbose -Message "Salvaging WMI repository"
                Start-Process -FilePath $WinMgmtPath -ArgumentList "/salvagerepository" -Wait
            }
        }
        else {
            foreach ($WMIPath in $WMIPaths) {
                if (Test-Path -Path $WMIPath -PathType Container) {
                    $MOFFiles = Get-ChildItem $WMIPath -Include "*.mof","*.mfl" -Recurse
                    foreach ($MOFFile in $MOFFiles) {
                        $CurrentMOFFilePath = (Join-Path -Path $WMIPath -ChildPath $MOFFile)
                        Write-Verbose -Message "Compiling MOF: $($CurrentMOFFilePath)"
                        Start-Process -FilePath (Join-Path -Path $env:SystemRoot -ChildPath "\System32\wbem\mofcomp.exe") -ArgumentList $CurrentMOFFilePath -Wait
                    }
                }
                else {
                    Write-Warning -Message "Unable to locate path '$($WMIPath)'"
                }
            }
            if ([System.Environment]::OSVersion.Version.Minor -eq 1) {
                Start-Process -FilePath (Join-Path -Path $env:SystemRoot -ChildPath "\System32\rundll32.exe") -ArgumentList wbemupgd,UpgradeRepository
            }
            else {
                Start-Process -FilePath (Join-Path -Path $env:SystemRoot -ChildPath "\System32\rundll32.exe") -ArgumentList wbemupgd,RepairWMISetup
            }
        }
    }
}
End {
    # Start Windows Management Instrumentation service
    Write-Verbose -Message "Starting Windows Management Instrumentation service"
    Start-Service -Name "Winmgmt"
 
    # Start previously running services that was stopped by this script
    foreach ($Service in $RunningServicesArrayList) {
        Write-Verbose -Message "Starting service '$($Service)'"
        Start-Service -Name $Service -ErrorAction SilentlyContinue
    }
}
In order to run the script, save the script above as Start-WMIMaintenance.ps1 in e.g. C:\Scripts.
1. Open an elevated PowerShell console.
2. Browse to the C:\Scripts.
3. Run the following command:
1
.\Start-WMIMaintenance.ps1 -Task Rebuild -Verbose
After that we had run the script on the device that we decided to rebuild the WMI repository on, we were successful in uninstalling the ConfigMgr client.
Here’s the output from the script, to give you a better idea of what it does:
124_2

댓글 없음:

댓글 쓰기