Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - ftpusers

Reply
 
Old 02-27-2007   #1 (permalink)
frank


 
 

ftpusers

I want create a script that after x amount of days any files under ftp share
will be deleted...

please help I am new to powershell


thanks

Frank

My System SpecsSystem Spec
Old 02-27-2007   #2 (permalink)
RichS


 
 

RE: ftpusers

Try something like this

## This script will remove files older than a given date

$folder = "c:\test" # folder to test
$NumDays = 30 # maximum age of file in days to allow

$CurDate = get-date # current date
$TestDate = $Curdate.AddDays(-$NumDays) # set TestDate

# ceate log file
$strData = "Files deleted from: " + $folder + " on " + $CurDate
$strData | out-file DeletedFiles.log

# get the files in the folder and determine if older than $NumDays

get-childitem $folder | foreach {

If ($_.GetType().Name -eq "FileInfo")
{

If ($_.LastWriteTime -lt $TestDate)
{
$strData = "File to delete: " + $_.Name + " " + $_.LastWriteTime
$strData | out-file -Append DeletedFiles.log
$_.Delete()
}

}



}

Change the folder & number of days to suit your needs

--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"frank" wrote:

> I want create a script that after x amount of days any files under ftp share
> will be deleted...
>
> please help I am new to powershell
>
>
> thanks
>
> Frank

My System SpecsSystem Spec
Old 02-27-2007   #3 (permalink)
frank


 
 

RE: ftpusers

I forgot to tell you that I want to delete folders from a sub-directory i.e
\abfolder \bbfolder


so if \ftp\abfolder or if bbfolder and so on had over 180 days it will delte
the files



Thanks



"RichS" wrote:

> Try something like this
>
> ## This script will remove files older than a given date
>
> $folder = "c:\test" # folder to test
> $NumDays = 30 # maximum age of file in days to allow
>
> $CurDate = get-date # current date
> $TestDate = $Curdate.AddDays(-$NumDays) # set TestDate
>
> # ceate log file
> $strData = "Files deleted from: " + $folder + " on " + $CurDate
> $strData | out-file DeletedFiles.log
>
> # get the files in the folder and determine if older than $NumDays
>
> get-childitem $folder | foreach {
>
> If ($_.GetType().Name -eq "FileInfo")
> {
>
> If ($_.LastWriteTime -lt $TestDate)
> {
> $strData = "File to delete: " + $_.Name + " " + $_.LastWriteTime
> $strData | out-file -Append DeletedFiles.log
> $_.Delete()
> }
>
> }
>
>
>
> }
>
> Change the folder & number of days to suit your needs
>
> --
> Richard Siddaway
> Please note that all scripts are supplied "as is" and with no warranty
> Blog: http://richardsiddaway.spaces.live.com/
> PowerShell User Group: http://www.get-psuguk.org.uk
>
>
> "frank" wrote:
>
> > I want create a script that after x amount of days any files under ftp share
> > will be deleted...
> >
> > please help I am new to powershell
> >
> >
> > thanks
> >
> > Frank

My System SpecsSystem Spec
Old 02-28-2007   #4 (permalink)
matthew.ashton@gmail.com


 
 

Re: ftpusers

On Feb 27, 3:53 pm, RichS <R...@discussions.microsoft.com> wrote:
> Try something like this
>
> ## This script will remove files older than a given date
>
> $folder = "c:\test" # folder to test
> $NumDays = 30 # maximum age of file in days to allow
>
> $CurDate = get-date # current date
> $TestDate = $Curdate.AddDays(-$NumDays) # set TestDate
>
> # ceate log file
> $strData = "Files deleted from: " + $folder + " on " + $CurDate
> $strData | out-file DeletedFiles.log
>
> # get the files in the folder and determine if older than $NumDays
>
> get-childitem $folder | foreach {
>
> If ($_.GetType().Name -eq "FileInfo")
> {
>
> If ($_.LastWriteTime -lt $TestDate)
> {
> $strData = "File to delete: " + $_.Name + " " + $_.LastWriteTime
> $strData | out-file -Append DeletedFiles.log
> $_.Delete()
> }
>
> }
>
> }
>
> Change the folder & number of days to suit your needs
>
> --
> Richard Siddaway
> Please note that all scripts are supplied "as is" and with no warranty
> Blog:http://richardsiddaway.spaces.live.com/
> PowerShell User Group:http://www.get-psuguk.org.uk
>
> "frank" wrote:
> > I want create a script that after x amount of days any files under ftp share
> > will be deleted...

>
> > please help I am new to powershell

>
> > thanks

>
> > Frank


Hi Frank,

If you use the -recurse flag on the Get-ChildItem cmdlet then it will
walk down the folder tree in the manenr you want.

so, replace "Get-ChildItem $folder" to "Get-ChildItem -recurse
$folder"

Matt

My System SpecsSystem Spec
Reply

Thread Tools



Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46