0 Replies Latest reply on Feb 22, 2016 6:02 PM by boyd

    Endpoint deletion script - powershell

    boyd

      Thought somebody might find this useful. I was looking for a easier way to delete multiple endpoints from an old ePO server once they were migrated to a new ePO server. Sadly my ancient ePO server version has a known bug that doesn't refresh the number of endpoints once the deletion occurs, but for anyone with a supported version of ePO, this might come in handy.

       

      1) download and copy curl.exe into c:\windows, so it is in your path

      2) modify location of text file and FQDN of the ePO server in the script to suit your requirements

      2) export a list of managed endpoints from the new server

      3) put the endpoint list in the text file, one name on each line

      4) run it against your OLD server to delete the old endpoints...the OLD server, I said...the OLD server!

       

      This can provide a way of knowing when your old server is empty of managed endpoints and can be decommissioned.

       

      Possible script upgrades:

       

      1) combine this to deploy an agent, check for the endpoint on the new server, then run the deletion on the old server if it exists as managed on the new server. I'm working on this.

      2) add logging to check results later and have a record of what happened. Probably using start-transcript and stop-transcript.

       

      Yes it is quick and dirty but seems to do the job (apart from the ePO refresh bug that I encountered, of course). I put a 5 second pause between each deletion so as not to cause a denial of service on the application server or the database server, but if your systems are beefy enough, by all means let it run at full speed and see how it goes.

       

      I take no responsibility for any harm this script does to your systems. If you're not sure about what you're doing, test it on a test lab setup or in your organisation's dev ePO environment, not production. Use at your own risk. You have been warned.

       

       

      # start of script

       

      $username = Read-host -prompt "Enter user ID"

      $securepass = read-host -assecurestring -prompt "Enter password to connect"

      $password = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Mar shal]::SecureStringToBSTR($securepass))

       

      foreach ($computername in get-content "c:\temp\deletions.txt")

       

      {

      write-host (get-date)

       

      curl -k -u $username":"$password https://server.yourdomain.local:8443/remote/system.delete?names="$computername"

       

      write-host "Sleeping 5 seconds..." -backgroundcolor red

       

      sleep 5

      }

       

      # end of script