locked
Need help with a script that Uninstalls SCCM CLient RRS feed

  • Question

  • Hello,

    I pieced together a script that uninstalls the SCCM client on remote machines listed in a text file. WHen I run the script the CCM client uninstalls fine. At the end of the uninstall the c:\windows\ccm and c:\windows\ccmsetup folders are still there and need to be deleted manually. I added in a few lines to the script to delete those folders but I keep getting a "The system cannot find the file specified." error for both RD commands. ANy suggestions? Is there a better way to write the script? TIA

    $Computers = Get-Content C:\CMClientProject\Computers.txt
    $PsExecPath = "C:\CMClientProject\PsExec.exe"
    ForEach($computer in $computers){
        $mystring=@"
        $($PsExecPath) \\$($computer) -u domain\user -p password "C:\Windows\ccmsetup\ccmsetup.exe" /uninstall
    "@
       $removeCCMSETUPFolder=@"
        $($PsExecPath) \\$($computer) -u domain\user -p password RD c:\Windows\ccmsetup /s /q
    "@
       $removeCCMfolder=@"
        $($PsExecPath) \\$($computer) -u domain\user -p password RD C:\Windows\CCM /s /q 
    "@

        invoke-expression $mystring
        invoke-expression $removeCCMSETUPFolder
        invoke-expression $removeCCMfolder
        
        
        
        
    }

    • Edited by Rich Ellis-MC Thursday, May 14, 2015 2:54 PM wrong script first time
    Thursday, May 14, 2015 2:53 PM

Answers

  • I see what you are saying and maybe it's because I didn't state my intent clearly enough.

    What I was looking for was direction on possibly removing the left over folders using a powershell command rather than PS exec.  I would like to use the remove-item command. The question is how to construct the statement and use the proper syntax within the script I provided.

    Rather than using:

    $removeCCMSETUPFolder=@"
        $($PsExecPath) \\$($computer) -u domain\user -p password RD c:\Windows\ccmsetup /s /q
    "@

    And then invoking it 

    Could I use something like:

    Remove-Item \\$computer\c$\windows\ccmsetup -Recurse -Force 






    Yes, Remove-Item \\$computer\c$\windows\ccmsetup -Recurse -Force  should work

    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.

    Don't Retire Technet

    • Proposed as answer by AnnaWY Friday, May 15, 2015 8:38 AM
    • Marked as answer by Rich Ellis-MC Friday, May 15, 2015 8:05 PM
    Thursday, May 14, 2015 5:02 PM

All replies

  • For PsExec issues you need to post here: http://forum.sysinternals.com/forum8.html


    \_(ツ)_/

    Thursday, May 14, 2015 3:06 PM
  • It's psexec within a powershell script. 
    Thursday, May 14, 2015 3:15 PM
  • It's psexec within a powershell script. 

    I recommend baking your PsExec into a loaf of bread and asking in a baking forum.

    Just because you wrapped it in PowerShell does not make it a PowerShell issue.  It is PsExec that is running the remoting.

    You are also trying to cascade multiple installers.  This is an installer issue.  You cannot normally cascade multiple installs.

    Since the target is SCCM then I recommend posting in the SCCM forum first.  You will find other who have tried this same thing who can advice you.


    \_(ツ)_/

    Thursday, May 14, 2015 4:24 PM
  • I see what you are saying and maybe it's because I didn't state my intent clearly enough.

    What I was looking for was direction on possibly removing the left over folders using a powershell command rather than PS exec.  I would like to use the remove-item command. The question is how to construct the statement and use the proper syntax within the script I provided.

    Rather than using:

    $removeCCMSETUPFolder=@"
        $($PsExecPath) \\$($computer) -u domain\user -p password RD c:\Windows\ccmsetup /s /q
    "@

    And then invoking it 

    Could I use something like:

    Remove-Item \\$computer\c$\windows\ccmsetup -Recurse -Force 





    Thursday, May 14, 2015 4:55 PM
  • I see what you are saying and maybe it's because I didn't state my intent clearly enough.

    What I was looking for was direction on possibly removing the left over folders using a powershell command rather than PS exec.  I would like to use the remove-item command. The question is how to construct the statement and use the proper syntax within the script I provided.

    Rather than using:

    $removeCCMSETUPFolder=@"
        $($PsExecPath) \\$($computer) -u domain\user -p password RD c:\Windows\ccmsetup /s /q
    "@

    And then invoking it 

    Could I use something like:

    Remove-Item \\$computer\c$\windows\ccmsetup -Recurse -Force 






    Yes, Remove-Item \\$computer\c$\windows\ccmsetup -Recurse -Force  should work

    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.

    Don't Retire Technet

    • Proposed as answer by AnnaWY Friday, May 15, 2015 8:38 AM
    • Marked as answer by Rich Ellis-MC Friday, May 15, 2015 8:05 PM
    Thursday, May 14, 2015 5:02 PM
  • That is a clearer question.  You asked in the OP with help uninstalling a program.  You should have asked how to remove folders.

    Don't be a helpless junior. Always start with help:

    Help Remove-Item -Full


    \_(ツ)_/


    • Edited by jrv Thursday, May 14, 2015 5:06 PM
    Thursday, May 14, 2015 5:05 PM
  • Hi,

    i have these 2 BAT files (made them before i even knew something about powershell) and it worked fine for my needs.

    1)
    @echo off
    :CYKLUS
    FOR /F "tokens=1 delims=," %%G IN (failedpc.txt) DO call :SUB %%G
    goto END

    :SUB
    psexec \\%1 -d c:\appl\sccm_client\ccmsetup /uninstall
    goto :EOF
    :END

    2)
    @echo off
    :CYKLUS
    FOR /F "tokens=1 delims=," %%G IN (failedpc.txt) DO call :SUB %%G
    goto END

    :SUB
    psexec \\%1 cmd /c taskkill /F /IM CcmExec.exe /IM Wuser.exe /IM SMSCliUI.exe /IM TSManager.exe /IM W32User.exe
    psexec \\%1 cmd /c net stop winmgmt /y
    psexec \\%1 cmd /c rmdir /S /Q c:\Windows\System32\CCM
    psexec \\%1 cmd /c rmdir /S /Q c:\Windows\System32\CCMSETUP

    goto :EOF
    :END

    Friday, May 15, 2015 9:12 AM