Jump to content

Script to delete computers that are offline


Recommended Posts

  • 2 months later...
  • 2 months later...
  • 2 weeks later...
  • 1 month later...
  • 1 month later...
  • 1 month later...
  • 6 months later...
  • 3 weeks later...
  • 1 month later...
Hi Everyone,

 

I am new to LabTech so please go easy on me.

 

How do I translate the .xml files into a script? Is there an import function? Do I just copy and paste the info from the xml into the new script dialogue?

 

DC

 

The .XML files are the format that LT exports/imports scripts as. Just hit Tools > Import > LT XML Expansion and point it to the scripts that you want to import.

 

If you don't want to chase around looking for it (post-import), I would say edit the XML and remove the values for the and at the beginning of the script before you import it. This will give the script a new ID when you add it, and place it in the root of the Scripts tree.

Link to post
Share on other sites
  • 4 weeks later...

Omg. Thank you Josh.

 

I wish to run the script every 30 days on machines that have not checked back within 90 days. Please let me know if I have this scripted correctly.

 

select computers.`computerid` from computers where computers.`LastContact` < DATE_ADD(Now(), INTERVAL -90 DAY)

 

Then I schedule this script to run against the LabTech server on a monthly cycle (say first day), would this be correct?

 

 

 

Thanks for all your help!

59ec943acdf9b_MonthlySchedule.png.9ab8dc98a9ec7228237b74a77a058e69.png

Link to post
Share on other sites
Omg. Thank you Josh.

 

I wish to run the script every 30 days on machines that have not checked back within 90 days. Please let me know if I have this scripted correctly.

 

select computers.`computerid` from computers where computers.`LastContact` < DATE_ADD(Now(), INTERVAL -90 DAY)

 

Then I schedule this script to run against the LabTech server on a monthly cycle (say first day), would this be correct?

 

[attachment=0]Monthly Schedule.png[/attachment]

 

Thanks for all your help!

 

 

That's it. Should do exactly as you described above, running on the 1st of each month

Link to post
Share on other sites
  • 3 weeks later...
  • 4 weeks later...

According to Clean up Inactive Agents script, its removing all the agents that haven't checked in for the past 30 days. I don't see 90 days being configured any where. Is that correct ? The Delete computer script is calling a stored procedure but has a note that says automatically delete computers, computer was offline for 90 days. So, if an agent didn't check in for the past 30 days, it will removed. Can someone please confirm this? Thanks !

Link to post
Share on other sites
  • 1 year later...
  • 2 weeks later...
Do we have a script that also creates a report of what machines were removed?

 

James,

 

I use the following script:

 

 

I have it set to run daily on my Automate server directly.

 

It not only removes all agents which have not checked in within the last 90 days, but it also delivers an e-mailed report to me with all of the agents which were removed which ends up looking like this when it's delivered to me:

 

 

 

The script attached should be totally sanitized, so it is safe to import without fear of it overwriting another script with the same ID or anything.

 

I have a separate group which contains just my Automate server which I run this script on (as well as others similar to it that I only want to run on my Automate server).

 

If you do something similar, you either need to update the advanced settings to include your username by adding the parameter, LTRUNBYUSER=YOURUSERNAME|, also as shown below. Or just modify the script on lines 19+24 to send the e-mail directly to whatever e-mail address you want instead of using the e-mail address associated with the username of the account which ran the script. If you don't do either, it will try and pull the e-mail address of the root user, which should be the default user that schedules scripts on groups when none other is specified, and so you won't actually receive the report in e-mail format.

 

agent_removal_email.png.ab191dd0afad9b66c45f8fb3df69c60b.png

agent_removal_groupscriptschedule.png.95ea0fe5e9202e4bfebca9a2c3fe59e6.png

Agent Removal over 90 days.zip

Link to post
Share on other sites

szkoda, the biggest issue with assigning to the monitor that I can see off the top of my head would be let's say that you have 20 agents all hitting 30 days old on the same day distributed throughout the day, you script would fire off 20 times during the day. If that is not a huge issue for you then technically I think it would be okay.

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...