Jump to content
Dew

Retire a computer programmatically?

Recommended Posts

I'm searching for a way to retire a computer in Automate as part of a larger script we run when a computer is removed from our environment. I assumed I would be able to effect something through the Automate API, but try as I might I couldn't find anything in the documentation that would allow me to do so.

I need to be able to retire offline computers, as in most cases when we are retiring a computer in our environment the computer is already in a state where the drive has been pulled and will never contact the network again; however, I do not want to do this through a Monitor that checks for last contact time, as we also have computers that may be offline in remote locations for extended periods of time.

From my understanding a computer can be retired by calling sp_DeleteComputer('%computerid%','message'), but our Automate server is hosted remotely and I do not know of any way I could do so.

Is what I'm trying to do even possible? Ideas would be appreciated.

Share this post


Link to post
Share on other sites

Hi, thank you for responding.

I had noticed I could use a SQL Execute function from within a script in Automate, I guess where I'm falling short is I'm unsure how I could trigger an Automate script to run against a specific computer from an external source such as a PowerShell script.

I did see that you can post to cwa/api/v1/Computers/{computerId}/CommandExecute in the API but I was unable to determine any way that I could run an Automate script against an offline computer using commands. Am I barking up the wrong tree entirely?

Edit: I somehow overlooked ScheduledScript_PostComputerScheduledScript, now my only issue is figuring out how to format the POST so as to not receive a nondescript unhandled exception, but that is unrelated to the original question.

Edited by Dew

Share this post


Link to post
Share on other sites

@Dew 

Hi Dew,

I am looking for an automated process to retire scripts very similar to what you have setup.

I would like to retire devices not seen online for last 90 days for specific service plans(I have EDF for this) and also ensure the process inputs the reason into automate of why it was retired for auditing purposes.

Is there anyway you can search your script for me to have access to it?

Share this post


Link to post
Share on other sites
On 12/11/2019 at 7:11 PM, Dew said:

Hi, thank you for responding.

I had noticed I could use a SQL Execute function from within a script in Automate, I guess where I'm falling short is I'm unsure how I could trigger an Automate script to run against a specific computer from an external source such as a PowerShell script.

I did see that you can post to cwa/api/v1/Computers/{computerId}/CommandExecute in the API but I was unable to determine any way that I could run an Automate script against an offline computer using commands. Am I barking up the wrong tree entirely?

Edit: I somehow overlooked ScheduledScript_PostComputerScheduledScript, now my only issue is figuring out how to format the POST so as to not receive a nondescript unhandled exception, but that is unrelated to the original question.

@Dew

Hi Dew,

 

Did you every get ScheduledScripts POST working? If so could you post a sample of your POST body?
 

I too and getting the "Encounterd unhandled exception" message. I've reviewed the docs at https://developer.connectwise.com/Products/Automate/REST/Computers but still getting hung up.

Any help would be greatly appreciated.

 

Thanks

Brian

Share this post


Link to post
Share on other sites

This one used to work, then stopped working, and ConnectWise wouldn't help or say why it stopped working. We are hosted with CW. This line just comes from the built in Offboarding script. Would really like a solution where web users can retire offline agents and we can automate the removal of offline agents. 

 

image.thumb.png.cc2030a3f30aef9b412b6b6bf61d54ad.png

Share this post


Link to post
Share on other sites

I've been seeing similar issues. We're also on a hosted environment and we've had a script in place for a long time that calls sp_DeleteComputer to retire machines that have been inactive for a period of time. Several months ago I noticed that machines weren't being removed that should be, and I've just now taken the time to research it further.  I installed a SQL Query Analyzer plugin so that I could step through the commands manually to see where things are failing, and it looks to me that we can no longer call that stored procedure.

Using the following I can see that the sp_DeleteComputer stored procedure still exists...

SELECT * 
FROM 
    INFORMATION_SCHEMA.ROUTINES 
WHERE 
    ROUTINE_NAME LIKE '%delete%'

...but when calling it manually I receive an error, presumably a similar error is occurring when it is called from the script.

call sp_DeleteComputer(851,'Automatically removed by Cleanup Inactive Agents. Computer was offline for more than 90 days')

image.png.e84ac78c917fc3213309b615cd972b44.png

Share this post


Link to post
Share on other sites
Posted (edited)

Call sp_DeleteComputer(@computerid@,'Removed by @LTRUNBYUSER@ on %when%')  < as an Offline Computer Script

This is still working for us but it simply 'Retires' the computer, does not delete.  Anybody know how to delete rather than just 'Retire'?

 

Edited by tvarvais

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...