Batch script

  • Need help on batch script to delete files located on different servers and should be addressed in one script.Lets say if I have .bak files on server A, Server B and Server C. I need to delete older files from all three servers from one script.

    Thanks,

  • Forget Windows Batch, PowerShell was built for tasks like this.

    Here is a one line command that does what you need. Add as many paths as you want and change the number of days as needed. Remove the -WhatIf when you are satisfied with the result and want to actually carry out the deletions.

    Get-ChildItem -Path "\\server1\path","\\server2\path1","\\server3\path" -Filter "*.bak" | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-7)} | Remove-Item -WhatIf

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • I really like batch files and I've used them for quite a few years. They can accomplish a lot and are quite a useful tool to have in your toolbox. I feel the same way about VB Script.

    That being said, opc.three is exactly right. PowerShell does some really cool things and I think it's the right tool for the job.

  • Ed Wagner (1/31/2013)


    I really like batch files and I've used them for quite a few years. They can accomplish a lot and are quite a useful tool to have in your toolbox. I feel the same way about VB Script.

    I figured this was worthy of a new discussion:

    http://www.sqlservercentral.com/Forums/Topic1414179-1351-1.aspx

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply