Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Remote delete synthax

  • 04-11-2009 10:14am
    #1
    Registered Users, Registered Users 2 Posts: 7,020 ✭✭✭


    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,020 ✭✭✭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