473,670 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can Someone Assist With Modifying a Simple PowerShell Script?

MCMike
11 New Member
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 4400
MCMike
11 New Member
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
8857
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
1958
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 not expected to check for everything. At any rate, the problem I am having with the following code is that it does not clear the fields once I press the SEND button. So can anyone here enlighten me as to what is causing the problem.
2
1651
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 developer), which is why I'm inquiring here. Anyways, first I'll show you the PHP code, and then I'll explain what kind of modification I need to have applied: ------------------------------------------------------------------------------ <?
1
1546
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 attend on a Friday. So, I need to have a web interface where each, say, can designate what Fridays they are not availabel in a given month, and waht particular friday would be their preference. Then, I attempt to schedule the one friday that they...
2
1487
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 do I get it running again? The script is shown below: Example url:
7
3252
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 - copy keyboard shortcuts box3 - copy workspace and a RUN button
3
1788
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 program. im using: f(x)=-0.6x^2+2.4x+5.5 f'(x)=-1.2x+2.4 eps=0.00001 initial guess=input by user the problem is something wrong with the answer.Can someone assist me???
6
2672
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 script fine from my Apache server but when I enter the record it says "Error - No Record Added " in order to run, I had to add "-w" next to the #!/usr/bin/perl statement, so now syntax is: #!/usr/bin/perl -w
0
1894
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 Powershell, how can you schedule it to run from the Windows Scheduler?
0
3314
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. The command prompt script that does this is: ECHO prime clean sourceanalyzer -b prime -clean ECHO prime translate sourceanalyzer -b prime %1 -debug -verbose -logfile prime.log...
0
8471
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8386
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8903
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8661
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6216
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4213
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4393
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2044
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1795
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.