473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Can Someone Assist With Modifying a Simple PowerShell Script?

MCMike
11
Hello Team,

I have a couple of simple PowerShell scripts that delete files older than 1 day from various folders (hard drive and UNC).

However, I am looking to modify them to run at a set time in the day so I don't have to trigger them manually.

Can someone assist with this? I have included the code from one of them. If this assistance is not available, thank you anyway!

Expand|Select|Wrap|Line Numbers
  1. #----- define parameters ---#
  2. #----- get current date ---#
  3. $Now = Get-Date
  4. #----- define amount of days ---#
  5. $Days = "1"
  6. #----- define folder where files are located ---#
  7. $TargetFolder = "C:\Backups\Temp\Daily Backups"
  8. #----- define Extension ---#
  9. $Extension = "*.zip"
  10. #----- define LastWriteTime parameter based on $Days ---#
  11. $LastWrite = $Now.Adddays(-$Days)
  12.  
  13. #----- get files based on lastwrite filter and specified folder ---#
  14. $Files = Get-Childitem $TargetFolder -Include $Extension -Recurse | Where {$_.LastWriteTime -le "$LastWrite"}
  15.  
  16.  
  17. foreach ($File in $Files)
  18.     {
  19.     if ($File -ne $Null)
  20.         {
  21.         write-host "Deleting File $File" -ForegroundColor "Red"
  22.         Remove-Item $File.FullName | out-null
  23.         }
  24.         else
  25.         {
  26.         Write-Host "No more files to delete!" -foregroundcolor "Green"
  27.         }
  28.     }
Cheers,

MCMike
Jun 15 '17 #1
1 4345
MCMike
11
Team,

Stand down on this request. I am pleasantly surprised that I am able to utilize the Task Scheduler. Most functions are administrator only on our tight-ass network, but for some reason there is no restriction with PowerShell and the Scheduler!

Thanks.

MCMike
Jun 16 '17 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Chuck Amadi | last post by:
Has anyone got a simple python script that will parse a linux mbox and create a large file to view . Cheers Chu
8
by: Sue | last post by:
Hello! I am back with another question. Remember I am a new JavaScript student and I am aware that this code does not check for all the possibilities and that as a "NEW" JavaScript student I am...
2
by: yvan | last post by:
I was wondering if someone here could help me with modifying this PHP template so that it does something very specific for me. My knowledge of PHP is very limited (I'm more of a Cold Fusion...
1
by: Ike | last post by:
Well, before I try to tackle this, just thought I would ask around if anyone is aware of something that might not do the following: I have 5 guys to schedule a lunch, each month, for them to...
2
by: usenet | last post by:
Hi, I have a simple php script which takes a variable from the url and prints it out. I've recently changed linux cpanel/whm severs and it no longer runs. What modules do I need to install/how...
7
by: Jason | last post by:
How would I create a simple vb script with a GUI interface to copy files from a fileserver to a PC. for example, I would have a form with Radio Buttons or Check Boxes box1 - copy prefs box2 -...
3
by: erry04 | last post by:
hi all,i just learn about newton raphson method and im thinking to create a code for it.(im not expert in c++,so my code could be wrong) For the function and it derivative,i hard code it in my...
6
by: auniqbal | last post by:
Hi, I am suing the "simple database script" from this website: http://bytes.com/serversidescripting/perl/tutorials/asimpledatabaseprogram/index.html See also file attached here. I can run the...
0
by: coreyfrankel | last post by:
I am looking for a PowerShell routine that will prune logfiles based on the date of my oldest backup. I keep a week of daily backups and wish to run this routine weekly. Also, as I am brand new to...
0
dbrewerton
by: dbrewerton | last post by:
Hello Experts! I am trying to build a script that performs automated scanning using HP Fortify from the command line. I thought I was passing my parameters correctly but something is not quite right....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.