Unix/Linux Go Back    


Windows & DOS: Issues & Discussions All Windows and DOS questions should go here as well. Discuss UNIX to Windows (Desktop or Server) here!

Powershell Script Help

Windows & DOS: Issues & Discussions


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 03-30-2012
freedavis freedavis is offline
Registered User
 
Join Date: Mar 2012
Last Activity: 30 March 2012, 1:36 PM EDT
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Powershell Script Help

Need some help getting this script to work. can someone help. I am trying to create a script that moves log files to another location and only keeps 60 days worth. please see script I started but having issue getting to work..


Code:
$TODAY=GET-DATE
GET-CHILDITEM C:\test\*.LOG | Where { $_.LastWriteTime.AddDays(31) -lt $TODAY } | MOVE-ITEM C:\Logfiles\Archive
GET-CHILDITEM F:\test\*.LOG | Where { $_.LastWriteTime.AddDays(31) -lt $TODAY } | MOVE-ITEM C:\Logfiles\Archive
GET-CHILDITEM E:\test\*.LOG | Where { $_.LastWriteTime.AddDays(31) -lt $TODAY } | MOVE-ITEM C:\Logfiles\Archive


Last edited by methyl; 03-30-2012 at 11:02 AM.. Reason: please use code tags
Sponsored Links
    #2  
Old Unix and Linux 03-30-2012
47shailesh 47shailesh is offline
Registered User
 
Join Date: Jul 2008
Last Activity: 21 October 2014, 12:11 PM EDT
Location: NY
Posts: 203
Thanks: 13
Thanked 39 Times in 38 Posts
try this

Code:
mv `find $log_dir -maxdepth 1 -mtime +60 -name \*LOG -type f | tr "\n" " "`  $destination

Sponsored Links
    #3  
Old Unix and Linux 03-30-2012
freedavis freedavis is offline
Registered User
 
Join Date: Mar 2012
Last Activity: 30 March 2012, 1:36 PM EDT
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
feedback

Thanks for this help. I am new to scripting. So, will this accomplish what the three lines of script I provided? And, can you help with what in your script I need to edit?

I am trying to moved files and archive from three c, e and F drive which log files reside. Then move them to one location folder on another server which I have setup as compressed.

Going to create a schduled task once I get this script right. Appreciate the help, really.
    #4  
Old Unix and Linux 03-30-2012
methyl methyl is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 8 June 2016, 9:58 PM EDT
Posts: 6,402
Thanks: 288
Thanked 676 Times in 645 Posts
What Shell is this?
It looks like Microsoft Windows Power Shell to me. If it is, you may get more joy on the Microsoft site.
Sponsored Links
    #5  
Old Unix and Linux 03-30-2012
freedavis freedavis is offline
Registered User
 
Join Date: Mar 2012
Last Activity: 30 March 2012, 1:36 PM EDT
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
yes

yes its windows powershell 2010
Sponsored Links
    #6  
Old Unix and Linux 03-30-2012
methyl methyl is offline
Registered User
 
Join Date: Mar 2008
Last Activity: 8 June 2016, 9:58 PM EDT
Posts: 6,402
Thanks: 288
Thanked 676 Times in 645 Posts
This site is https://www.unix.com and you are in the unix and Linux forums.
Sponsored Links
    #7  
Old Unix and Linux 03-30-2012
freedavis freedavis is offline
Registered User
 
Join Date: Mar 2012
Last Activity: 30 March 2012, 1:36 PM EDT
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
ok

thx..
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help with shell script - Calling a script through script Siddheshk Shell Programming and Scripting 0 04-18-2011 05:14 AM
Does PowerSHell have *stat command analogs? Xcislav Windows & DOS: Issues & Discussions 1 03-31-2011 12:08 PM
create a shell script that calls another script and and an awk script magikminox Shell Programming and Scripting 0 06-26-2008 02:50 AM



All times are GMT -4. The time now is 04:00 PM.