Scripting help for copying new items added to a set of directories - powershell

I have a set of folders which have new files being added to them regularly, but I have to process those files as they come in. This can be a time consuming process to dig into each folder one by one. I need to figure out how to write a script that will filter out the new files, and copy them into a new directory.
So far I have figured out how to use the Get-ChildItem -Path -Recurse command in powershell to list the new items in the corresponding folders as shown in the third script on this Microsoft page.
So I can see the new files in their folders. How do I copy those items to the destination folder while replicating their original folder structure? I want to be able to recreate the original folders so that I can just overwrite the originals with the edited versions later.

I discovered robocopy, and was able to use it to solve my problem. The /maxage:x option was perfect for my needs.

Related

Delete duplicates files with powershell based on their name and file contents

I am really new to powershell, really need help with this.
I have a directory with multiple folders with multiple files, some files in different folders are having the same name with or without the same content. All I need to do is to filter out all the files with the same name and with the same content and move them to the other folder.
I tried the way using in this link
https://sid-500.com/2020/04/26/find-duplicate-files-with-powershell/
the issue here is that get-filehash can find the duplicates by contents, but not by name (for example: dir\a\a.txt and dir\a\b.txt will be considered as duplicates but I want dir\a\a.txt and dir\b\a.txt be the duplicates) and also it cannot identify empty files.

Getting NTFS permissions through Powershell and piping the output to set the same permissions in a different location

I am moving CIFS share files and subfolders from one system to another, and I want to set the top level folder at the destination to have same ACLs as the top level folder at the source. In some cases this is up to 25 users and groups.
Is there a way to get the ACLs from the source top level folder, and pipe that output so it is applied to the top level destination folder?
You can copy an ACL very easily:
Get-Acl -Path <SourceFolder> | Set-Acl -Path <DestinationFolder>
But this isn't very eloquent. It will only take the ACL from one folder and apply it to another. Given you are going to copy a whole tree your milage may vary.
Robocopy is often used in these situations with the /COPYALL parameter. You can create the tree without copying with /CREATE. You may have to tinker around to get it to do only one folder. Hard to say without knowing the particulars of your project, but if you're interested check the help file.
I'd also point out, there is an awesome NTFS module here. I use it all the time it's very capable, and very easy to script around.
Let me know if this is helpful.

Extracting Multiple 7z Files Overrides Same Folder

I'm currently working on a project where I take multiple 7z files and extract the contents of these files in a folder named the same way as the 7z file itself. I also apologize if something like this has been answered already; I spent time trying to investigate this issue but I can't seem to find anyone else who has had a similar issue.
For example:
a1.7z -> <targetpath>/a1/<contents within a1.7z>
The following shell line: a1.7z | % {& "C:\Program Files\7-Zip\7z.exe" "x" $_.fullname "-o<targetpath>\a1" -y -r}
Works like a dream, but only for one 7z file. However, whenever I start extracting a second 7z file, it won't create a new folder but instead will continue to add into the same first folder that is created; second folder is never made. When I manually highlight all of the 7z files I want to extract, right click and select "Extract to "*\", it does what I would like it to do but I can't figure out how to script this action. I should also mention that some of the 7z files, when extracted, can contain subfolders of the same name. I'm not sure if this is throwing off the recursion cycle, but I'm assuming this might be the case.
Any help or advice on this topic would be greatly appreciated!
If you get all the .7z files as IOFileInfo objects (Using get-ChildItem) you can use Mathias comment, as one way to do this with the pipeline, but I recommend you put this inside a loop and look for a better way to choose the names of the folders I.e. "NofFolder_$_.BaseName" just in case of more than 1 folder with the same name.
It really depends on the format you want.

Create windows script to traverse all subfolders of some folder, and delete a certain folder and all of it's contents if it exists

here's the trick. Supposing I want to free up some space, and run that script in F:\UnrealProjects, which has a bit over 50-60 subfolders, I would like that script to traverse all of it's subfolders, check whether it contains a folder named Binaries, Build, Intermediate and delete everything in it including the folder(s) itself it it exists.
I'm not quite lazy to do it manually once, but when reopening some projects, they do partially or fully rebuild themselves and that eats up space since I really don't need them fully built at all times. I just need to have them archived :) And build only the ones i do want to have built.
Thanks for any help in advance guys (or gals), it's appreciated alot.
If however someone has a better idea to retag this question, I'm all ears and very open to suggestions.
Something like this, should do it
ls -Recurse -Include Build,Intermediates,Binaries -Attribute Directory | Remove-Item -Force -Recurse

Copy all files of one type from directory into one folder

This is a new one for me so I'm pretty much flying blind.
I have a folder at 192.168.1.2\mainFolder that contains folder1, folder2, and folder3. Inside each of those folders are a handful of different file extentions, and a couple of files of each type. I need to take all files that exist inside mainFolder of the .dep type, and copy them to 192.168.1.2\copyFolder
copyFolder will not have any folders inside it, but just many many files.
What is the best way to go about doing this? I have been told by TPTB that robocopy would be helpful, however I have never used robocopy and thought you guys may know of something better
So you don't want .dep files inside folder1, 2 etc.? Robocopy / xcopy is usually a good choice. Powershell is slow for such a simple operation. If you just want the .dep files in mainfolder but not those inside the subfolders, try:
robocopy \\192.168.1.2\mainFolder \\192.168.1.2\copyFolder *.dep