locked
SMSTSPostAction - Running twice? RRS feed

  • Question

  • Backstory: Trying to remove the SCCM Client after OSD for our student computers. To do so I have created a powershell script that is started via SMSTSPostAction. The script copies SMSTS.log for troubleshooting purposes and removes directories and logs that the ccmsetup.exe does not remove when uninstalling. The SMSTS.log file indicates that the variable is set correctly.

    The Problem: It appears that the SMSTSPostAction is running twice for some reason. My script kicks off (as indicated by the log) and stops about 1/100th second later and then starts again and abruptly stops yet again.  In the script I have it logging what is happening. I can manually run the script without any issues. Any ideas?

    Log file that is called by script:

    TSCleanup.ps1 that is called:

    #############################################################################
    # Author  : Tyler Cox
    # Email: 
    #
    # Version : 1.0
    # Created : 08/10/2017
    # Modified : 
    #
    # Purpose : This script runs at the end of the OSD task sequence to 
    #           do the following:
    #
    #           1. Copy SMSTS log so it is not lost
    #           2. Removes the ConfigMgr Client
    #           3. Cleans up by removing leftover folders and shortcuts
    #
    ##############################################################################
    
    $logdir = "$env:SystemRoot\ISU\"
    $log = $logdir + "FinalTS.log" #log file which saves date
    $logLine = "============================================================================================"
    $error.Clear()
    $SMSTSlogSource = "C:\Windows\CCM\Logs\SMSTS.log"
    $SMSTSlogDest = "C:\Windows\ISU\SMSTS.log"
    
    #function for log writing
    function Write-Log {
    	param (
    		[Parameter( Mandatory=$true)][string]$logdata,
    		[Parameter( Mandatory=$true)][string]$logfile
    		)
    	
    	#Check to see if the specified log file exists
    	$fileexist = Test-Path $logdir
    	If ($fileexist -eq $false) {
    		New-Item -ItemType Directory $logdir
            }
        #Does the log file exist?
        If ((Test-Path $log) -eq $False) {
                $item = New-Item -ItemType file "$log" | out-null
                }
    	
    	#Prepare and write the data to the log file
    	$now = Get-Date -format s
    	$fileexist = Test-Path $log
    	If ($fileexist -eq $True) {
    		$logstring = $now+" >> "+$logdata
    		$logstring | Out-File -Append $log
    		}
    	}#endfunc
    
    
    Write-Log -logfile $log -logdata $logLine
    Write-Log -logfile $log -logdata "Sleeping for 30 seconds.."
    Start-Sleep -Seconds 30 #sleep for safety measures
    
    #Copy the log file so it is not lost
    If (!(Test-Path -Path $SMSTSlogDest)) { #test if log is already in destination
        Write-Log -logfile $log -logdata "Attempting to copy SMSTS.log"
        Try {
            Copy-Item -Path $SMSTSlogSource -Destination $SMSTSlogDest -Force -ErrorAction Stop
            }
        Catch {
            write-log -logfile $log -logdata "Error: Unable to copy SMSTS.log"
            }
        If (!$error) {
            write-log -logfile $log -logdata "Successfully copied SMSTS.log"
            }
        }
    Else {
        Write-Log -logfile $log -logdata "Warning: SMSTS.log does not exist or has already been copied"
        }
    
    #Remove SCCM Client
    $error.Clear()
    If (Get-Service -Name 'SMS Agent Host') { #Test if SCCM is installed and running
        Write-Log -logfile $log -logdata "Attempting to uninstall SCCM Client"
        Try {
            start-process "C:\Windows\ccmsetup\ccmsetup.exe" -ArgumentList @( '/uninstall') -wait -ErrorAction Stop
            }
        Catch {
            write-log -logfile $log -logdata "Error: Unable to uninstall SCCM Client"
            }
        If (!$error) {
            write-log -logfile $log -logdata "Successfully uninstalled SCCM Client"
            }
        }
    Else {
        Write-Log -logfile $log -logdata "Warning: SCCM Client has already been uninstalled"
        }
    
    Write-Log -logfile $log -logdata "Sleeping for 60 seconds so client gets uninstalled.."
    Start-Sleep -Seconds 60 #sleep to allow client to be fully uninstalled
    
    
    #Cleanup ccmsetup folder
    $error.Clear()
    If (Test-Path -Path "C:\Windows\ccmsetup") { #tests if path exists
        Write-Log -logfile $log -logdata "Attempting to remove ccmsetup folder"
        Try {
            remove-item "C:\Windows\ccmsetup" -Recurse -Force -ErrorAction Stop
            }
        Catch {
            write-log -logfile $log -logdata "Error: Unable to remove ccmsetup Folder"
            }
        If (!$error) {
            write-log -logfile $log -logdata "Successfully removed ccmsetup folder"
            }
        }
    Else {
        Write-Log -logfile $log -logdata "Warning: Ccmsetup folder does not exist or has been removed already"
        }
    
    
    #Cleanup Software Center shortcut
    $error.Clear()
    If (Test-Path -Path "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft System Center") { #tests if shortcut exists
        Write-log -logfile $log -logdata "Attempting to remove Software Center shortcut"
        Try {
            remove-item "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft System Center" -Force -Recurse -ErrorAction Stop
            }
        Catch {
            write-log -logfile $log -logdata "Error: Unable to remove Software Center shortcut"
            }
        If (!$error) {
            write-log -logfile $log -logdata "Successfully removed Software Center shortcut"
            }
        }
    Else {
        Write-Log -logfile $log -logdata "Warning: Software Center shortcut does not exist or has been removed already"
        }
    
    
    
    #Cleanup MININT folder
    $error.Clear()
    If (Test-Path -Path "C:\MININT") { #tests if path exists
        Write-Log -logfile $log -logdata "Attempting to remove MININT folder"
        Try {
            remove-item "C:\MININT" -Force -Recurse -ErrorAction Stop
            }
        Catch {
            write-log -logfile $log -logdata "Error: Unable to remove MININT folder"
            }
        If (!$error) {
            write-log -logfile $log -logdata "Successfully removed MININT folder"
            }
        }
    Else {
        Write-Log -logfile $log -logdata "Warning: MININT folder does not exist or has beenr emoved already"
        }
    
    
    #Cleanup CCM folder
    $error.Clear()
    If (Test-Path -Path "C:\Windows\CCM") { #tests if path exists
    Write-Log -logfile $log -logdata "Attempting to remove CCM folder"
        Try {
            remove-item C:\Windows\CCM -Force -Recurse -ErrorAction Stop
            }
        Catch {
            write-log -logfile $log -logdata "Error: Unable to remove CCM folder"
            }
        If (!$error) {
            write-log -logfile $log -logdata "Successfully removed CCM folder"
            }
        }
    Else {
        Write-Log -logfile $log -logdata "Warning: CCM folder does not exist or has been removed already"
        }
    
    
    Write-Log -logfile $log -logdata "Finished TSCleanup Script"
    Write-Log -logfile $log -logdata $logLine

    Tuesday, August 15, 2017 1:24 PM

Answers

  • I solved my own problem by doing the following:

    1) Created a Simple Task in Task Scheduler to run a program. Set it to run once. Set the program as "powershell.exe" and the "arguments" as "-ExecutionPolicy ByPass -File "C:\Windows\Temp\TSCleanup.ps1"

    2) I created a Run command Line step that schedules the task. "SCHTASKS.exe /CREATE /RU system /XML "C:\Windows\Temp\SMSTSPostAction.xml" /TN "Cleanup Script""

    3) I set SMSTSPostAction variable to run the scheduled task. "schtasks.exe /run /TN "Cleanup Script"

    • Marked as answer by tcox8 Thursday, August 17, 2017 8:11 PM
    Thursday, August 17, 2017 8:11 PM

All replies

  • https://docs.microsoft.com/en-us/sccm/osd/understand/task-sequence-steps#BKMK_PrepareConfigMgrClientforCapture "Starting in Configuration Manager version 1610, the Prepare ConfigMgr Client step completely removes the Configuration Manager client"

    Torsten Meringer | http://www.mssccmfaq.de

    Tuesday, August 15, 2017 1:46 PM
  • Thanks but this isn't for capture. This is for deployment. The ConfigMgr client needs to be removed after the deployment to the machine.
    Tuesday, August 15, 2017 1:48 PM
  • Can you please share the complete SMSTS log file?

    Wednesday, August 16, 2017 4:15 AM
  • SMSTS.log was split into 3 files.

    File 1 (SMSTS.log)

    <![LOG[Successfully submitted event to the Status Agent.]LOG]!><time="10:10:46.419+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="event.cpp:862"> <![LOG[CheckInit(), HRESULT=87d00202 (e:\nts_sccm_release\sms\framework\ccmtask\eventexec.cpp,455)]LOG]!><time="10:10:46.434+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="eventexec.cpp:455"> <![LOG[CCM::Task::QueueEvent(L"SiteRoleCycleEvent", NULL, sEventData.c_str()), HRESULT=87d00202 (e:\nts_sccm_release\sms\framework\ccmhttp\ccmhttperror.cpp,355)]LOG]!><time="10:10:46.434+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="ccmhttperror.cpp:355"> <![LOG[Failed to queue event on HTTP/HTTPS failure for server 'MYSERVER.MYDOMAIN.com'. Error 0x87d00202]LOG]!><time="10:10:46.434+240" date="08-16-2017" component="LocationServices" context="" type="2" thread="4032" file="ccmhttperror.cpp:355"> <![LOG[RequestResponseImpl( szUrl, L"GET", szHeaders, 0, 0, 0, 0, uFlags, &pbResponse, &ulResponseLen), HRESULT=80072f0c (e:\nts_sccm_release\sms\framework\ccmhttp\ccmhttpget.cpp,537)]LOG]!><time="10:10:46.434+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="ccmhttpget.cpp:537"> <![LOG[GetURLSyncInStreamEx2(szUrl, szHeaders, uFlags, &spStream), HRESULT=80072f0c (e:\nts_sccm_release\sms\framework\ccmhttp\ccmhttpget.cpp,612)]LOG]!><time="10:10:46.434+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="ccmhttpget.cpp:612"> <![LOG[spHttpGet->GetURLSyncInStringEx( sUrl.c_str(), ulSendFlags, &csResponse), HRESULT=80072f0c (e:\nts_sccm_release\sms\framework\locationservices\lsutilities\lsexports.cpp,2051)]LOG]!><time="10:10:46.434+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="lsexports.cpp:2051"> <![LOG[CCMGetGlobalService(&spService), HRESULT=87d00219 (e:\cm1702_rtm\sms\framework\core\ccmcore\ccmconditions.cpp,83)]LOG]!><time="10:10:46.434+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="ccmconditions.cpp:83"> <![LOG[Processing network cost from NLM]LOG]!><time="10:10:46.434+240" date="08-16-2017" component="LocationServices" context="" type="1" thread="4032" file="ccmutillib.cpp:6317"> <![LOG[NLM_CONNECTION_COST_UNRESTRICTED]LOG]!><time="10:10:46.434+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="ccmutillib.cpp:5820"> <![LOG[MapNLMCostDataToCCMCost() returning Cost 0x1]LOG]!><time="10:10:46.434+240" date="08-16-2017" component="LocationServices" context="" type="1" thread="4032" file="ccmutillib.cpp:5901"> <![LOG[Detecting if client is on the internet.]LOG]!><time="10:10:46.434+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="ccmhttpget.cpp:1044"> <![LOG[Client is not set to use any webproxy.]LOG]!><time="10:10:46.434+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="ccmhttpget.cpp:1058"> <![LOG[GET: Host=MYSERVER.MYDOMAIN.com, Path=/SMS_MP/.sms_aut?SITESIGNCERT, Port=443, Protocol=https, Flags=1536, Options=63]LOG]!><time="10:10:46.434+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="ccmhttpget.cpp:1188"> <![LOG[HRESULT_FROM_WIN32(dwErrorCode), HRESULT=80072f0c (e:\nts_sccm_release\sms\framework\ccmhttp\ccmhttpget.cpp,1509)]LOG]!><time="10:10:46.465+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="ccmhttpget.cpp:1509"> <![LOG[Failed in WinHttpReceiveResponse API, ErrorCode = 0x2f0c]LOG]!><time="10:10:46.465+240" date="08-16-2017" component="LocationServices" context="" type="3" thread="4032" file="ccmhttpget.cpp:1509"> <![LOG[[CCMHTTP] ERROR: URL=https://MYSERVER.MYDOMAIN.com/SMS_MP/.sms_aut?SITESIGNCERT, Port=443, Options=63, Code=12044, Text=ERROR_WINHTTP_CLIENT_AUTH_CERT_NEEDED]LOG]!><time="10:10:46.465+240" date="08-16-2017" component="LocationServices" context="" type="1" thread="4032" file="ccmhttperror.cpp:291"> <![LOG[[CCMHTTP] ERROR INFO: StatusCode=600 StatusText=]LOG]!><time="10:10:46.465+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="ccmhttperror.cpp:302"> <![LOG[Raising event: instance of CCM_CcmHttp_Status { ClientID = "GUID:446D70A1-C613-4956-8F42-A2CBEF0BEEDF"; DateTime = "20170816141046.465000+000"; HostName = "MYSERVER.MYDOMAIN.com"; HRESULT = "0x80072f0c"; ProcessID = 4028; StatusCode = 600; ThreadID = 4032; }; ]LOG]!><time="10:10:46.465+240" date="08-16-2017" component="LocationServices" context="" type="1" thread="4032" file="event.cpp:840"> <![LOG[Successfully submitted event to the Status Agent.]LOG]!><time="10:10:46.465+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="event.cpp:862"> <![LOG[CheckInit(), HRESULT=87d00202 (e:\nts_sccm_release\sms\framework\ccmtask\eventexec.cpp,455)]LOG]!><time="10:10:46.465+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="eventexec.cpp:455"> <![LOG[CCM::Task::QueueEvent(L"SiteRoleCycleEvent", NULL, sEventData.c_str()), HRESULT=87d00202 (e:\nts_sccm_release\sms\framework\ccmhttp\ccmhttperror.cpp,355)]LOG]!><time="10:10:46.465+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="ccmhttperror.cpp:355"> <![LOG[Failed to queue event on HTTP/HTTPS failure for server 'MYSERVER.MYDOMAIN.com'. Error 0x87d00202]LOG]!><time="10:10:46.465+240" date="08-16-2017" component="LocationServices" context="" type="2" thread="4032" file="ccmhttperror.cpp:355"> <![LOG[RequestResponseImpl( szUrl, L"GET", szHeaders, 0, 0, 0, 0, uFlags, &pbResponse, &ulResponseLen), HRESULT=80072f0c (e:\nts_sccm_release\sms\framework\ccmhttp\ccmhttpget.cpp,537)]LOG]!><time="10:10:46.465+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="ccmhttpget.cpp:537"> <![LOG[GetURLSyncInStreamEx2(szUrl, szHeaders, uFlags, &spStream), HRESULT=80072f0c (e:\nts_sccm_release\sms\framework\ccmhttp\ccmhttpget.cpp,612)]LOG]!><time="10:10:46.465+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="ccmhttpget.cpp:612"> <![LOG[spHttpGet->GetURLSyncInStringEx( sUrl.c_str(), ulSendFlags, &csResponse), HRESULT=80072f0c (e:\nts_sccm_release\sms\framework\locationservices\lsutilities\lsexports.cpp,2051)]LOG]!><time="10:10:46.465+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="lsexports.cpp:2051"> <![LOG[CCMGetGlobalService(&spService), HRESULT=87d00219 (e:\cm1702_rtm\sms\framework\core\ccmcore\ccmconditions.cpp,83)]LOG]!><time="10:10:46.465+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="ccmconditions.cpp:83"> <![LOG[Processing network cost from NLM]LOG]!><time="10:10:46.465+240" date="08-16-2017" component="LocationServices" context="" type="1" thread="4032" file="ccmutillib.cpp:6317"> <![LOG[NLM_CONNECTION_COST_UNRESTRICTED]LOG]!><time="10:10:46.465+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="ccmutillib.cpp:5820"> <![LOG[MapNLMCostDataToCCMCost() returning Cost 0x1]LOG]!><time="10:10:46.465+240" date="08-16-2017" component="LocationServices" context="" type="1" thread="4032" file="ccmutillib.cpp:5901"> <![LOG[Detecting if client is on the internet.]LOG]!><time="10:10:46.465+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="ccmhttpget.cpp:1044"> <![LOG[Client is set to use webproxy if available.]LOG]!><time="10:10:46.481+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="ccmhttpget.cpp:1052"> <![LOG[GET: Host=MYSERVER.MYDOMAIN.com, Path=/SMS_MP/.sms_aut?SITESIGNCERT, Port=443, Protocol=https, Flags=512, Options=63]LOG]!><time="10:10:46.481+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="ccmhttpget.cpp:1188"> <![LOG[Converting target URL scheme to HTTPS.]LOG]!><time="10:10:46.481+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="ccmwebproxy.cpp:120"> <![LOG[Target URL scheme is HTTPS: https://MYSERVER.MYDOMAIN.com/SMS_MP/.sms_aut?SITESIGNCERT]LOG]!><time="10:10:46.481+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="ccmwebproxy.cpp:126"> <![LOG[Trying without proxy.]LOG]!><time="10:10:46.481+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="ccmwebproxy.cpp:451"> <![LOG[HRESULT_FROM_WIN32(dwErrorCode), HRESULT=80072f0c (e:\nts_sccm_release\sms\framework\ccmhttp\ccmhttpget.cpp,1509)]LOG]!><time="10:10:46.497+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="ccmhttpget.cpp:1509"> <![LOG[Failed in WinHttpReceiveResponse API, ErrorCode = 0x2f0c]LOG]!><time="10:10:46.497+240" date="08-16-2017" component="LocationServices" context="" type="3" thread="4032" file="ccmhttpget.cpp:1509"> <![LOG[[CCMHTTP] ERROR: URL=https://MYSERVER.MYDOMAIN.com/SMS_MP/.sms_aut?SITESIGNCERT, Port=443, Options=63, Code=12044, Text=ERROR_WINHTTP_CLIENT_AUTH_CERT_NEEDED]LOG]!><time="10:10:46.497+240" date="08-16-2017" component="LocationServices" context="" type="1" thread="4032" file="ccmhttperror.cpp:291"> <![LOG[[CCMHTTP] ERROR INFO: StatusCode=600 StatusText=]LOG]!><time="10:10:46.497+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="ccmhttperror.cpp:302"> <![LOG[Raising event: instance of CCM_CcmHttp_Status { ClientID = "GUID:446D70A1-C613-4956-8F42-A2CBEF0BEEDF"; DateTime = "20170816141046.497000+000"; HostName = "MYSERVER.MYDOMAIN.com"; HRESULT = "0x80072f0c"; ProcessID = 4028; StatusCode = 600; ThreadID = 4032; }; ]LOG]!><time="10:10:46.497+240" date="08-16-2017" component="LocationServices" context="" type="1" thread="4032" file="event.cpp:840"> <![LOG[Successfully submitted event to the Status Agent.]LOG]!><time="10:10:46.497+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="event.cpp:862"> <![LOG[CheckInit(), HRESULT=87d00202 (e:\nts_sccm_release\sms\framework\ccmtask\eventexec.cpp,455)]LOG]!><time="10:10:46.497+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="eventexec.cpp:455"> <![LOG[CCM::Task::QueueEvent(L"SiteRoleCycleEvent", NULL, sEventData.c_str()), HRESULT=87d00202 (e:\nts_sccm_release\sms\framework\ccmhttp\ccmhttperror.cpp,355)]LOG]!><time="10:10:46.497+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="ccmhttperror.cpp:355"> <![LOG[Failed to queue event on HTTP/HTTPS failure for server 'MYSERVER.MYDOMAIN.com'. Error 0x87d00202]LOG]!><time="10:10:46.497+240" date="08-16-2017" component="LocationServices" context="" type="2" thread="4032" file="ccmhttperror.cpp:355"> <![LOG[RequestResponseImpl( szUrl, L"GET", szHeaders, 0, 0, 0, 0, uFlags, &pbResponse, &ulResponseLen), HRESULT=80072f0c (e:\nts_sccm_release\sms\framework\ccmhttp\ccmhttpget.cpp,537)]LOG]!><time="10:10:46.497+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="ccmhttpget.cpp:537"> <![LOG[GetURLSyncInStreamEx2(szUrl, szHeaders, uFlags, &spStream), HRESULT=80072f0c (e:\nts_sccm_release\sms\framework\ccmhttp\ccmhttpget.cpp,612)]LOG]!><time="10:10:46.497+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="ccmhttpget.cpp:612"> <![LOG[spHttpGet->GetURLSyncInStringEx( sUrl.c_str(), ulSendFlags, &csResponse), HRESULT=80072f0c (e:\nts_sccm_release\sms\framework\locationservices\lsutilities\lsexports.cpp,2051)]LOG]!><time="10:10:46.497+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="lsexports.cpp:2051"> <![LOG[Workgroup client is in Unknown location]LOG]!><time="10:10:46.497+240" date="08-16-2017" component="LocationServices" context="" type="1" thread="4032" file="lsad.cpp:1173"> <![LOG[LSGetInternetMode: Unknown]LOG]!><time="10:10:46.497+240" date="08-16-2017" component="LocationServices" context="" type="0" thread="4032" file="lsad.cpp:5054"> <![LOG[Current Internet Management Point is MYSERVER.MYDOMAIN.com with Version 8498 and Capabilities: <Capabilities SchemaVersion="1.0"><Property Name="SSL" Version="1"/><Property Name="SSLState" Value="63"/></Capabilities>]LOG]!><time="10:10:46.497+240" date="08-16-2017" component="ClientLocation" context="" type="0" thread="4032" file="smsclientclass.cpp:1168"> <![LOG[Successfully connected to MP MYSERVER.MYDOMAIN.com:80]LOG]!><time="10:10:46.497+240" date="08-16-2017" component="TSManager" context="" type="1" thread="4032" file="utils.cpp:5367"> <![LOG[Access handle will be read from _SMSTSActiveRequestHandle]LOG]!><time="10:10:46.497+240" date="08-16-2017" component="TSManager" context="" type="1" thread="4032" file="tsmanagerutils.cpp:100"> <![LOG[Access handle: {E6A6C731-D788-4703-923C-2388EBBB6B73}]LOG]!><time="10:10:46.497+240" date="08-16-2017" component="TSManager" context="" type="1" thread="4032" file="tsmanagerutils.cpp:111"> <![LOG[Attempting to release request using {E6A6C731-D788-4703-923C-2388EBBB6B73}]LOG]!><time="10:10:46.497+240" date="08-16-2017" component="TSManager" context="" type="1" thread="4032" file="tsmanagerutils.cpp:119"> <![LOG[CoCreateInstance succeeded]LOG]!><time="10:10:46.512+240" date="08-16-2017" component="TSManager" context="" type="1" thread="4032" file="tsmanagerutils.cpp:133"> <![LOG[pISoftwareExecutionRequestMgr->ReleaseRequest(ActiveRequestGUID), HRESULT=80004005 (e:\nts_sccm_release\sms\client\tasksequence\tsmanager\tsmanagerutils.cpp,136)]LOG]!><time="10:10:46.512+240" date="08-16-2017" component="TSManager" context="" type="0" thread="4032" file="tsmanagerutils.cpp:136"> <![LOG[ReleaseRequest failed with error code 0x80004005]LOG]!><time="10:10:46.512+240" date="08-16-2017" component="TSManager" context="" type="3" thread="4032" file="tsmanagerutils.cpp:136"> <![LOG[Task Sequence Manager could not release active TS request. code 80004005]LOG]!><time="10:10:46.512+240" date="08-16-2017" component="TSManager" context="" type="2" thread="4032" file="tsmanagerutils.cpp:166"> <![LOG[Command line for extension .exe is "%1" %*]LOG]!><time="10:10:46.528+240" date="08-16-2017" component="TSManager" context="" type="0" thread="4032" file="commandline.cpp:229"> <![LOG[Set command line: "PowerShell.exe" -ExecutionPolicy ByPass -File "C:\Windows\Temp\TSCleanup.ps1"]LOG]!><time="10:10:46.528+240" date="08-16-2017" component="TSManager" context="" type="0" thread="4032" file="commandline.cpp:732"> <![LOG[Executing command line: "PowerShell.exe" -ExecutionPolicy ByPass -File "C:\Windows\Temp\TSCleanup.ps1"]LOG]!><time="10:10:46.528+240" date="08-16-2017" component="TSManager" context="" type="1" thread="4032" file="commandline.cpp:828"> <![LOG[Process completed with exit code 0]LOG]!><time="10:10:46.559+240" date="08-16-2017" component="TSMBootstrap" context="" type="1" thread="3908" file="commandline.cpp:1124"> <![LOG[Exiting with return code 0x00000000]LOG]!><time="10:10:46.559+240" date="08-16-2017" component="TSMBootstrap" context="" type="1" thread="3908" file="tsmbootstrap.cpp:1270"> <![LOG[Process completed with exit code 0]LOG]!><time="10:10:46.559+240" date="08-16-2017" component="OSDSetupHook" context="" type="1" thread="3812" file="commandline.cpp:1124"> <![LOG[Task sequence completed 0x00000000]LOG]!><time="10:10:46.559+240" date="08-16-2017" component="OSDSetupHook" context="" type="1" thread="3812" file="basesetuphook.cpp:1609"> <![LOG[Resume SCCM Client.]LOG]!><time="10:10:46.559+240" date="08-16-2017" component="OSDSetupHook" context="" type="1" thread="3812" file="basesetuphook.cpp:1264"> <![LOG[Uninstalling Setup Hook]LOG]!><time="10:10:48.122+240" date="08-16-2017" component="OSDSetupHook" context="" type="1" thread="3812" file="basesetuphook.cpp:1644"> <![LOG[Removing setup hook from registry.]LOG]!><time="10:10:48.122+240" date="08-16-2017" component="OSDSetupHook" context="" type="0" thread="3812" file="vistasetuphook.cpp:143"> <![LOG[Successfully removed C:\WINDOWS\system32\OSDGINA.DLL]LOG]!><time="10:10:48.122+240" date="08-16-2017" component="OSDSetupHook" context="" type="1" thread="3812" file="basesetuphook.cpp:1321"> <![LOG[Successfully removed C:\WINDOWS\system32\OSDSETUPHOOK.EXE]LOG]!><time="10:10:48.122+240" date="08-16-2017" component="OSDSetupHook" context="" type="1" thread="3812" file="basesetuphook.cpp:1321"> <![LOG[Successfully removed C:\WINDOWS\system32\_SMSOSDSetup]LOG]!><time="10:10:48.122+240" date="08-16-2017" component="OSDSetupHook" context="" type="1" thread="3812" file="basesetuphook.cpp:1358"> <![LOG[End program: PowerShell.exe -ExecutionPolicy ByPass -File "C:\Windows\Temp\TSCleanup.ps1"]LOG]!><time="10:10:48.122+240" date="08-16-2017" component="OSDSetupHook" context="" type="1" thread="3812" file="basesetuphook.cpp:1658"> <![LOG[Successfully finalized logs to SMS client log directory from C:\WINDOWS\CCM\Logs]LOG]!><time="10:10:48.137+240" date="08-16-2017" component="OSDSetupHook" context="" type="1" thread="3812" file="tslogging.cpp:1911">


    Wednesday, August 16, 2017 3:01 PM
  • The other files are too large to copy. Let me know if you think you need them and I'll try to find a place to upload them and post links.
    Wednesday, August 16, 2017 3:06 PM
  • In the log lines that you posted, there is only one instance where the post action was run:

    <![LOG[Executing command line: "PowerShell.exe" -ExecutionPolicy ByPass -File "C:\Windows\Temp\TSCleanup.ps1"]LOG]!><time="10:10:46.528+240" date="08-16-2017" component="TSManager" context="" type="1" thread="4032" file="commandline.cpp:828">

    I suggest that you instead handle the re-run in you powershell script.

    For example, write to a file or registry when your script runs. At the very start of your script, you can check for this file or registry to detect whether or not the script should run.

    Wednesday, August 16, 2017 8:05 PM
  • Btw, uninstalling the SCCM client from the TS is never a supported scenario because the task sequence engine itself depends on the SCCM client when in the full OS.

    Wednesday, August 16, 2017 8:10 PM
  • You are correct that the log shows it running once but that is it setting the variable. And you are also correct that the TS is dependent on the SCCM client but the whole reason for the variable SMSTSpostaction is to do an action after the TS finishes. Unfortunately there is no log that records what happens with the SMSTSpostaction variable other than the SMSTS.log showing setting the variable and showing that the command executed.
    Wednesday, August 16, 2017 8:19 PM
  • I solved my own problem by doing the following:

    1) Created a Simple Task in Task Scheduler to run a program. Set it to run once. Set the program as "powershell.exe" and the "arguments" as "-ExecutionPolicy ByPass -File "C:\Windows\Temp\TSCleanup.ps1"

    2) I created a Run command Line step that schedules the task. "SCHTASKS.exe /CREATE /RU system /XML "C:\Windows\Temp\SMSTSPostAction.xml" /TN "Cleanup Script""

    3) I set SMSTSPostAction variable to run the scheduled task. "schtasks.exe /run /TN "Cleanup Script"

    • Marked as answer by tcox8 Thursday, August 17, 2017 8:11 PM
    Thursday, August 17, 2017 8:11 PM
  • I spend quite a while yesterday trying to figure this out. This morning, I created a Powershell function to take care of the "evil twin" process:

    Function Kill-EvilTwin
    {
        # Set properties
        $strPathProcessIDList = "$env:windir\Temp\ProcessIDList.txt"
        $blnKeepWaiting = $true
        $intTimeBailout = 10000
        $intTimeStep = 100
        $intTimeElapsed = 0
    
        # Write current Process ID to file
        $PID | Out-File -FilePath $strPathProcessIDList -Append -Force -ErrorAction Stop
    
        # Loop until bailout time is reached
        Do
        {
            # Get all Process IDs in file
            $arrProcesses = Get-Content -Path $strPathProcessIDList
    
            # Check if there is more than one Process ID in the list and if the current Process ID is the first one
            If( $arrProcesses.Count -gt 1 -and $arrProcesses[0] -eq $PID)
            {
            
                # Kill the second Process ID in the list
                Get-Process -Id $arrProcesses[1] | Stop-Process -Force
    
                # Wait no longer
                $blnKeepWaiting = $false
            }
            Else
            {
    
                # Sleep for a while
                Start-Sleep -Milliseconds $intTimeStep
    
                # Increase elapsed time
                $intTimeElapsed += $intTimeStep
    
                # Check for timeout
                If( $intTimeElapsed -ge $intTimeBailout) { $blnKeepWaiting = $false}
            }
        }
        Until( $blnKeepWaiting -eq $false)
    
        # Remove Process ID list file
        Remove-Item -Path $strPathProcessIDList -Force
    }
    
    Kill-EvilTwin
    
    "I won!"

    To try it out, save the code as Kill-EvilTwin.ps1, start two seperate command prompt windows (as administrator) and run the following command in both windows a few seconds apart:

    powershell.exe -ExecutionPolicy Bypass -NoProfile -File .\Kill-EvilTwin.ps1

    Thursday, November 9, 2017 9:18 AM