Troubleshooting ConfigMgr 2012 Client Migration using Powershell (Part 4)

In this post, we’ll look at another cause of ConfigMgr client upgrade failure – the SMS Task Sequence Agent service is running.  It can sometimes happen that a task sequence gets ‘stuck’ and never completes, but the SMS Task Sequence Agent service (smstsmgr) is started and never stopped.  Usually I have found that it ‘freezes’ because it is waiting for software updates to pause before it can continue, and for some reason that doesn’t happen.  A similar issue is described in this post: http://setspn.blogspot.co.uk/2013/07/sccm-task-sequence-software-updates.html?sm_au=iVV7Sp7LVprV5k7F.  Usually I use the ‘reset the Paused SW distribution cookie’ option in Roger Zander’s SCCM Client Center to remedy that.

If the SMS Task Sequence Agent service is running when the ConfigMgr client installation process attempts to uninstall the previous client, it will fail, and stop the entire process.

Symptoms

This is how to detect this problem:

  • The ccmsetup.exe and associated SCCM client files are all successfully downloaded to the client, the ccmsetup service is started but the installation fails
  • The ccmsetup.log contains a line near the end that says ‘installation failed with error code 1603‘. Error code 1603 is ‘fatal error during installation’.
  • The client.msi_uninstall.log contains a line like this: ERROR: Failed to stop the ‘smstsmgr’ service, hr=8007041c

The following Powershell script can be run against a machine where to identify if it has this problem.  It will search the log files for the error string, and report if it finds it or not.


<#
Ths script searches the client.msi_uninstall.log on a remote machine to identify if the "ERROR: Failed to stop the 'smstsmgr' service" line is present in the log.
Requires admin rights to remote machine
#>

$ComputerName = "DB-MyLaptop"

$tsmanager = select-string -path \\$ComputerName\C$\Windows\ccmsetup\Logs\client.msi_uninstall.log -pattern "ERROR: Failed to stop the 'smstsmgr' service" -allmatches –simplematch
if ($tsmanager -eq $true)
{
write-host "The error 'Failed to stop the 'smstsmgr' service' IS present in the client.msi_uninstall.log on $ComputerName. Kill the tsmanager.exe process on the machine before attempting SCCM client upgrade." -ForegroundColor Yellow
}
if ($tsmanager -eq $null)
{
write-host "The error 'Failed to stop the 'smstsmgr' service' is NOT present in the client.msi_uninstall.log on $ComputerName."
}

Resolution

The resolution is to stop the SMS Task Sequence Agent service on the client machine by killing the ‘tsmanager.exe‘ process. You can then push-install the client again from the SCCM Console, or you can trigger it manually from the client itself using process described below.

Kill the tsmanager Process Remotely

The following Powershell script will detect if the tsmanager process is running and kill it if it is. Enter the computername in the variable.

<#
Ths script checks whether the 'Task Sequence Manager' process is running on a client machine and kills it if it is.
For troubleshooting SCCM client upgrade issues.
#>

$ComputerName = "DB-MyLaptop"

# Test connectivity to the computer
if (Test-Connection -Quiet -Count 2 -ComputerName $ComputerName -ErrorAction SilentlyContinue)
{$Online = "Yes"}else{$Online = "No"}
if ($Online -eq "No")
{write-host "$ComputerName is not online!"}
if ($Online -eq "Yes")
{
# Start Remote Registry Service to allow Get-Process to run
(Get-Service -ComputerName $ComputerName -Name RemoteRegistry).Start()

# Check if tsmanager is running
if (Get-Process tsmanager -ComputerName $ComputerName)
{$tsmanager = "Yes"}else{$tsmanager = "No"}

# if yes, kill it...
If ($tsmanager -eq "Yes")
{
Write-Host "tsmanager process exists"
Write-Host "killing process..."
Invoke-Command -computername $ComputerName {Stop-Process -processname "TSManager" -Force}
}

# if no...
if ($tsmanager -eq "No")
{
Write-Host "tsmanager process does not exist"
}

# Stop Remote Registry Service
(Get-Service -ComputerName $ComputerName -Name RemoteRegistry).Stop()
}

Delete the ccmsetup Service Remotely

Once you have killed the tsmanager process, it is possible to manually trigger the installation of the SCCM client remotely using Powershell. This uses the ccmsetup.exe file that has already been copied to the machine. But first you must kill any existing ccmsetup process and service. This script will do that. Enter the computername in the variable.


<#
Ths script checks whether the 'ccmsetup' service is present on a client machine and deletes it if it is.
#>
$ComputerName = "DB-MyLaptop"

# Test connectivity to the computer
if (Test-Connection -Quiet -Count 2 -ComputerName $ComputerName -ErrorAction SilentlyContinue)
{$Online = "Yes"}else{$Online = "No"}
if ($Online -eq "No")
{write-host "$ComputerName is not online!"}
if ($Online -eq "Yes")
{
# Start Remote Registry Service to allow Get-Process to run
(Get-Service -ComputerName $ComputerName -Name RemoteRegistry).Start()

# Check if ccmsetup is running
if (Get-Service ccmsetup -ComputerName $ComputerName -ErrorAction SilentlyContinue)
{$ccmsetup = "Yes"}else{$ccmsetup = "No"}

# if yes...
If ($ccmsetup -eq "Yes")
{
Write-Host "ccmsetup service exists"
$Status = (Get-Service -ComputerName $ComputerName -Name ccmsetup -ErrorAction SilentlyContinue).Status
write-host "ccmsetup service is $status"
if ($Status = "Stopped")
{
write-host "Deleting service..."
$service = Get-WmiObject -ComputerName $ComputerName -Class Win32_Service -Filter "Name='ccmsetup'"
$service.delete() | Out-Null
(Get-Service ccmsetup -ComputerName $ComputerName -ErrorAction SilentlyContinue)
}
}

# if no...
if ($ccmsetup -eq "No")
{
Write-Host "ccmsetup service does not exist"
}

# Stop Remote Registry Service
(Get-Service -ComputerName $ComputerName -Name RemoteRegistry).Stop()
}

Trigger the Client Installation Again

This script will trigger the installation of the SCCM client from the ccmsetup.exe already copied to the machine by a previous push-installation attempt. Enter the computername in the variable, and the SMS Site Code at the relevant place.


<#
Ths script remotely triggers an SCCM client upgrade installation from files already cached on the machine.
Requires Powershell remoting
#>
$ComputerName = "DB-MyLaptop"
# Test connectivity to the computer
if (Test-Connection -Quiet -Count 2 -ComputerName $ComputerName -ErrorAction SilentlyContinue)
{$Online = "Yes"}else{$Online = "No"}
if ($Online -eq "No")
{write-host "$ComputerName is not online!"}
if ($Online -eq "Yes")
{
$s = New-PSSession -ComputerName $ComputerName

Write-Host "Starting SCCM Client installation on $Computername"
# Main script
Invoke-Command -Session $s -ScriptBlock `
{
Start-Process -FilePath "C:\windows\ccmsetup\ccmsetup.exe" -ArgumentList "SMSSITECODE=PS1" -Verbose
}
Remove-PSSession $s
}

In my environment, I included these activities in the Client Checks script we ran previously, so if this error was detected, it would be automatically remedied.  This makes troubleshooting a lot easier!

Next time, we’ll look at WMI issues.

Advertisements

One thought on “Troubleshooting ConfigMgr 2012 Client Migration using Powershell (Part 4)

  1. This is awesome. Three years I have been trying to figure out why I could not turn off the damn task sequence service. The most obvious answer was right in front of me.

    Just saved us hours of work as we roll out the client to our domain.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s