Remove unwanted Sage temp files

Asset 32

Powershell script to remove Sage temp files

Posted on 19 July 2018 by Beaming Support

If you host Sage files on a file server, then you may have noticed that the most recent versions of Sage leave temp files in the C:WindowsTemp folder. This has occurred in at least the latest two versions of Sage Accounts and will eat up a lot of storage space over time.

If you value your C drive space, then the script below can be run once a week (on a weekend). The script will find and remove all files created within the month and named using the Sage standard, which are located within the C:WindowsTemp folder.

Powershell

Open Notepad and paste in the following:

#Set $month as current month, 2 digit string

$Month = Get-Date -UFormat %m

#Sets $Year variable to current year, 4 digit string

$Year = Get-Date –Uformat %Y

 

#Sets $Sage variable as the file name needed, 2018-06*

$Sage = $Year + “-” + $month + “*”

 

#Retrieves a list of folders and removes them,

Get-ChildItem -Path “C:WindowsTemp” -Filter $Sage | Remove-Item –Recurse

Save this file as ‘SageRemoval.ps1’ in a folder that is easy to find (C:Script for example).

BAT file

Then open notepad again and write in the following:

@echo off

Powershell.exe -executionpolicy remotesigned -file C:ScriptSageRemoval.ps1

Save this file in the same location for easiness and call it ‘SageRemove.bat’.

Open Task scheduler and create a new basic task. Name it ‘Sage file removal’ and tick ‘Run whether user is logged on or not’. Create a new trigger, set Weekly and then choose the next Sunday at a reasonable time. Set the task to recur every Sunday, hit enable and OK.

Under actions, choose New, then Browse to the folder that you saved the bat file in. Leave arguments and start in as blank and press OK. Press Ok to the task and enter the domain credentials to save the task.

That’s it. Now once a week the Sage temp files will be automatically removed and your C drive won’t fill up causing you a headache.

All of our Powershell knowledge base articles are available in one handy guide – download now

 

‘It means we can work much quicker with clients and have more real-time information’
Mark Weeks-Pearson Partner, Ashdown Hurrey Accountants

How has digital technology helped accountants improve services?

Read our Digital Transformation in Accounting report to find out.

Related

The future of accounting: how embracing technology can help your firm to stay one step ahead 

What’s next in accounting technology?

How should accountants respond to cyber crime?

How will real time data change accounting?

How can advisory services add value for clients?

A calculator laying beside some accounts

Find the answers to these and more in our report ‘How can accountants benefit from technological change?’ – FREE to download now

Accountants2_Subscribe
This field is for validation purposes and should be left unchanged.