Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Remote delete synthax

  • 04-11-2009 11:14AM
    #1
    Registered Users, Registered Users 2 Posts: 7,033 ✭✭✭


    Does anybody know the synthax for a script to remotely delete files on a network share based on the age/date attribute of the files ?

    21/25



Comments

  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    You'll need to clarify a bit. Are you accessing the server through ssh? (e.g. putty) and do you know what kind of OS it's running? Usually a network server will be running linux or solaris, that kind of thing. In which case you can use the "find" command to remove files based on their age.


  • Registered Users, Registered Users 2 Posts: 7,033 ✭✭✭uch


    It's just a network share on a NAS, it's shared as a UNC path, the files are SQL backupsthat are shipped to the share, I can setup a maintenence plan to delete them off the local Server(Windows 2003) but SQL Wont delete remote files for me, so I wanted to setup a batch file that could be called by a scheduled task to delete files older than 8 weeks, as I don't want the NAS share to fill up.

    21/25



  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    Ah, gotchta. So you have the share mounted as a drive on your windows machine and you want to write a .bat file to find files older than 8 weeks and remove them.

    This looks like it should do the trick for you. I'm not really a .bat man myself so there might be an easier way.

    This is the key part:
    Get-ChildItem C:\Test | Select-Object Name, @{Name="Age";Expression={ (((Get-Date) - $_.CreationTime).Days) }} |
    Sort-Object Age
    

    There's probably a way of altering that expression for Select-Object to get ones with a date that's > 56 days or whatever.


Advertisement