Powershell Script Help

 
Thread Tools Search this Thread
Special Forums Windows & DOS: Issues & Discussions Powershell Script Help
# 1  
Old 03-30-2012
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 12:02 PM.. Reason: please use code tags
# 2  
Old 03-30-2012
try this
Code:
mv `find $log_dir -maxdepth 1 -mtime +60 -name \*LOG -type f | tr "\n" " "`  $destination

# 3  
Old 03-30-2012
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 03-30-2012
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.
# 5  
Old 03-30-2012
yes

yes its windows powershell 2010
# 6  
Old 03-30-2012
This site is https://www.unix.com and you are in the unix and Linux forums.
# 7  
Old 03-30-2012
ok

thx..
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

powershell script to unix shell script conversion.

Here is a powershell script to use restful API to create ticket in our ticketing tool. Can anyone please convert it to a shell script sothat, I can run it in Unix servers, below is the code: $body = @{ Customer= ''test' Summary= 'test summary' Impact= '4-Minor/Localized' ... (2 Replies)
Discussion started by: pandeybhavesh18
2 Replies

2. UNIX for Advanced & Expert Users

Running Powershell Script from Linux through Cygwin

Hello Experts, I am creating a run time powershell script on Linux machine and copying that powershell script to Windows machine. To connect to windows through "ssh", I am using Cygwin tool. To make the connection password less I copied my public in authorized_keys in windows Administrator... (5 Replies)
Discussion started by: shekhar_4_u
5 Replies

3. Shell Programming and Scripting

Execute powershell script with UNIX

Hi I have a powershell script which is checking whether a windows service is running (as shown below) function FuncCheckService { $ServiceName = 'pgsql-9.2' $arrService = Get-Service -Name $ServiceName if ($arrService.Status -eq 'Running') { Write-Output... (8 Replies)
Discussion started by: simpsa27
8 Replies

4. Shell Programming and Scripting

Powershell script to monitor windows process

Hello Friend, I am not expert in power shell scripting. I nee custom powershell script which check if given process is running on windows machine or not. will use it in nagios to monitor that process. (0 Replies)
Discussion started by: ghpradeep
0 Replies

5. Windows & DOS: Issues & Discussions

Powershell + office 365

Hello ! I am looking for powershell guys. I have lot of office365 users ,and i need add/remove calendar items from powershell. my users have multiple calendars. how can i select calendar ,and how can i add / remove item to selected calendar. PS C:\appl\o365calendar> get-mailboxfolder... (0 Replies)
Discussion started by: zoldkovacs
0 Replies

6. Shell Programming and Scripting

Bash script - cygwin (powershell?) pull from GitHub API Parse JSON

All, Have a weird issue where i need to generate a report from GitHub monthly detailing user accounts and the last time they logged in. I'm using a windows box to do this (work issued) and would like to know if anyone has any experience scripting for GitAPI using windows / cygwin / powershell?... (9 Replies)
Discussion started by: ChocoTaco
9 Replies

7. Windows & DOS: Issues & Discussions

To find a value in atext file using powershell

Hi All, i have a VB script which help me in downloading the text file(mail attachment) to my local drive from outlook.i want to check some values in the text file. for ex A date1 count count miss 2/25/2014 42 42 0 B date2 ... (0 Replies)
Discussion started by: mahesh300182
0 Replies

8. Windows & DOS: Issues & Discussions

Help with PowerShell

I am very not knowledgeable with regards to Windows, and even more so with PowerShell, but I'm hoping someone can help me with what should be a fairly simple script. Remove all local accounts matching a given regular expression It seems like I'd need the following combined... Somehow... ... (0 Replies)
Discussion started by: Vryali
0 Replies
Login or Register to Ask a Question