absolute beginner help please!!!!

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 15 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
daflex
Posts: 4
Last visit: Wed Jul 16, 2008 6:12 pm

absolute beginner help please!!!!

Post by daflex »

Ok, I come here completely cap in hand knowing almost next to nothing about scripting and having done nowt more with PS than open it up and fire off a few basic commands.

But from what I have read PS is the new daddy on the block regarding scripting and (in my mind at least) what I would need the script to do would be pretty simple (for someone who knows what they are doing with scripts anyway..........)

Basically I need a script(s) that can go through a directory and all its sub-directorys and output to a file any file that was modified before a particular date, or after a paticular date, or between particular dates.

To put the problem itself into context have just recently completed a server migration but for whatever reason some files that the users work on are more recent on the old server than the new, but as multiple users work on the same files sorting out what is what wont be an easy task (they are all just spreadsheet files afaik). What appears to have happened is some users have updated files on the new server where as others have updated on the old.

Thankfully both servers were only on the network together for about a week so the disparity of data wont be too out of hand and it also means the script will only need to deal with days in july.

Any help would be massively appriciated and will save hours and hours of work crawling through directorys and subdirectorys!!! (and may also begin to teach me a bit about scripting, I do want to learn but I dont think I can get up to speed in about 24 hours, which is about the sort of time frame I have to sort this out......!!!!

Thanks in advance!!!!!!!!
User avatar
daflex
Posts: 4
Last visit: Wed Jul 16, 2008 6:12 pm

absolute beginner help please!!!!

Post by daflex »

Ok, I come here completely cap in hand knowing almost next to nothing about scripting and having done nowt more with PS than open it up and fire off a few basic commands.

But from what I have read PS is the new daddy on the block regarding scripting and (in my mind at least) what I would need the script to do would be pretty simple (for someone who knows what they are doing with scripts anyway..........)

Basically I need a script(s) that can go through a directory and all its sub-directorys and output to a file any file that was modified before a particular date, or after a paticular date, or between particular dates.

To put the problem itself into context have just recently completed a server migration but for whatever reason some files that the users work on are more recent on the old server than the new, but as multiple users work on the same files sorting out what is what wont be an easy task (they are all just spreadsheet files afaik). What appears to have happened is some users have updated files on the new server where as others have updated on the old.

Thankfully both servers were only on the network together for about a week so the disparity of data wont be too out of hand and it also means the script will only need to deal with days in july.

Any help would be massively appriciated and will save hours and hours of work crawling through directorys and subdirectorys!!! (and may also begin to teach me a bit about scripting, I do want to learn but I dont think I can get up to speed in about 24 hours, which is about the sort of time frame I have to sort this out......!!!!

Thanks in advance!!!!!!!!
User avatar
dmerida
Posts: 16
Last visit: Fri Oct 30, 2009 5:38 am

absolute beginner help please!!!!

Post by dmerida »

You got it =)

get-childitem -path <insert directory here> -recurse | where{$_.lastwritetime -gt "7/1/2008"} > samplefile.txt


A few things:

- You can choose where the output file is going to go (ex. c:samplefile.txt). If there are spaces in the file directory, enclose the location in double quotes (ex. "c:documents and settingsmeserver migrationsamplefile.txt")

- The wonderful thing about PowerShell is that it has a very useful help feature to aid you in understanding the syntax. PowerShell was designed to encourage users to explore and better understand it. For example, type Get-Help Get-Childitem -detailed at the prompt to get not only an explanation of how Get-Childitem works, but examples of how to use it too. If you're not sure what the name of a cmdlet is, type Get-Command at the prompt and you will be given a list of all cmdlets available to you.

Hope this helps! Feel free to post questions, that's why we're here =)
User avatar
jeremyg
Posts: 23
Last visit: Mon Mar 18, 2024 6:07 am

absolute beginner help please!!!!

Post by jeremyg »

And if you want to only have the filename in the text file (and not other file info):
get-childitem -path <mypath> -recurse | where{$_.lastwritetime -gt "6/1/2008"} | format-table -property name > samplefile.txt

Also, since you're learning, I recommend using full commands as much as possible so that you can get used to powershell. So instead of using the ">" simple to output to file, use:| out-file samplefile.txt
User avatar
daflex
Posts: 4
Last visit: Wed Jul 16, 2008 6:12 pm

absolute beginner help please!!!!

Post by daflex »

wow =| a single line! do i take the -recurse switch takes care of the subdirectorys??
User avatar
dmerida
Posts: 16
Last visit: Fri Oct 30, 2009 5:38 am

absolute beginner help please!!!!

Post by dmerida »

Yup, -recurse is the subdirectories. If you ever want to look for hidden files and folders, the -force switch will take care of that.
User avatar
daflex
Posts: 4
Last visit: Wed Jul 16, 2008 6:12 pm

absolute beginner help please!!!!

Post by daflex »

cool =D now am i correct that the -gt is for files greater than, what would be the switch for less than?

(not that im too lazy to find out, just too busy right now!!!)

....always the way, you need to find things out and learn when you have the least amount of time to address the problem!!!!
This topic is 15 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked