locked
Uninstall Configuration Manager Client Remotely using Powershell & PSEXEC RRS feed

  • Question

  • On a local machine, to uninstall configuration manager client you need to switch to c:\windows\ccmsetup on the local machine and then execute "ccmsetup.exe /uninstall" to uninstall the CCM client. I need to do this with many clients.

    Manually, if I run "PSEXEC.exe CMD \\COMPUTERNAME then  CD C:\windows\ccmsetup and then run CCMSETUP.EXE /Uninstall it works.

    I just can't figure out how to put this all together in a script.

    This is the script I wrote and its not working. 

    $RemoteComputers = get-content "J:\!Scripts and Utils\Scripts\PowerShell\CCM-PS\CCM-PSComputers.txt"
    ForEach ($Computer in $RemoteComputers)
    {
       Invoke-Command -Scriptblock {"J:\!Scripts and Utils\Scripts\PowerShell\CCM-PS\psexec.exe \\$Computer CMD | C:\windows\ccmsetup\ccmsetup.exe /uninstal"}
    
    }
    TIA





    Wednesday, June 21, 2017 4:00 PM

All replies

  • If these computers have a ccm client why don't you use SCCM to uninstall it? .... it's made for.  ;-)

    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    Wednesday, June 21, 2017 5:41 PM
  • I have. I migrated hardware,upgraded to the latest version of CM and server OS, created a new site and used a different site code. The client upgrade process from SCCM worked well but some clients are very stubborn and only migrate when you run a complete uninstall of the client and install the new client manually. I have tried many times to install from SCCM and selecting "Uninstall Existing CM client before the client is installed" to no avail. 

    If I get on the machine or PSEXEC to the machine and uninstall then install that way it works. I have 180 clients in this condition so taking the time to manually PSEXEC into each one would be too time consuming.

    Wednesday, June 21, 2017 5:49 PM
  • Create a package with the uninstall command and deploy it to the stubborn machines, then deploy the new client.

    Also, your script is using Invoke-Command to connect to the remote computer, to call psexec to connect to the remote computer? This makes no sense.

    You should just need something like the following, if that is the approach you want to take.

    $RemoteComputers = get-content "J:\!Scripts and Utils\Scripts\PowerShell\CCM-PS\CCM-PSComputers.txt"
    $scriptBlock = { C:\windows\ccmsetup\ccmsetup.exe /uninstall }
    Invoke-Command -Scriptblock $scriptBlock -ComputerName $RemoteComputers


    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. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''





    • Proposed as answer by jrv Wednesday, June 21, 2017 6:34 PM
    • Marked as answer by Rich Ellis-MC Wednesday, June 21, 2017 7:24 PM
    • Unmarked as answer by Rich Ellis-MC Wednesday, June 21, 2017 8:44 PM
    • Edited by clayman2 Thursday, June 22, 2017 1:36 PM typo
    Wednesday, June 21, 2017 5:57 PM
  • I have tried that. Worked on 1 client, errored out on 48 others so far. If you (or anyone) have any ideas on how I can accomplish this by script I would appreciate suggestions. I am a powershell newbie as you can tell. I know the basic cmdlets and basic scripting but I don't use it enough to know all them.



    Wednesday, June 21, 2017 7:27 PM
  • Hi,

    >>I have tried that. Worked on 1 client, errored out on 48 others so far.

    What errors?

    If you showing us the errors, i suppose that could be helpful for further assistance.

    Best regards,

    Andy


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Thursday, June 22, 2017 6:25 AM
  • I have tried that. Worked on 1 client, errored out on 48 others so far. If you (or anyone) have any ideas on how I can accomplish this by script I would appreciate suggestions. I am a powershell newbie as you can tell. I know the basic cmdlets and basic scripting but I don't use it enough to know all them.



    Did you try the script I posted or build a package in SCCM to uninstall?

    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. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

    Thursday, June 22, 2017 11:37 AM
  • Hi,

    I tried both and neither worked. The script didn't work at all and the package worked on 1 machine but errored off on the rest. 

    Thanks

    Thursday, June 22, 2017 1:02 PM
  • The deployment comes back with error code 1.

    The script will run with no errors but nothing happens on the clients as I am monitoring the ccmsetup\logs folder and I see no activity.
    Thursday, June 22, 2017 1:19 PM
  • I just noticed in my script, which I copied from you, the uninstall switch is not correct as you have uninstal, and it should be uninstall. I have modified my script above for this.

    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. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

    Thursday, June 22, 2017 1:35 PM