Hope you all intelligent people are well. i am new to this still learning so you can understand i am no where know PS scripts like you guys. so i thought to request you guys if you could help me. i am looking to write a script where it will zip the same name files into one zip folder for example…
abc_1.pdf, abc_2.pdf, abc_3.pdf, ABC_ltr.doc
def_1.pdf, def_2.pdf, def_3.pdf, def_ltr.doc…and so on
so basically i want to zip all the “abc” file name files into one zip and all the “def” files name into another zip. this is simple i guess for you guys as there is not other criteria of time or date or anything. simply create a zip folder with the same name files and also name the zip folder with the same name.
We can surely help but we will not do your job. So you will have to do the actual work.
We are used to get some code to debug. So please show your code and the complete error messages if you get some. (Please format your code as code as described in the very first post on top of the list of posts in this forum: Read Me Before Posting! You’ll be Glad You Did! … and please format the error messages as code as well if you post some)
To get you started you should read the help for Get-ChildItem, Foreach-Object and Compress-Archive.
You should read each of these help topics completely including the examples to learn how to use them.
Thank you for posting the code, what is the issue you are facing at this time? Is it working as expected or are you receiving errors? What is the issue you face at this time with your script? I would also not change the directory to the location unless totally necessary, you are already pulling the full path. I would look at adding some error handling as well, before placing this in production. How will your script handle if there are no directories/files that match your where-object filter?
Before:
cd C:\inetpub\wwwroot\dev82\
$SOURCE = Get-ChildItem * -Directory|Where-Object {$_.FullName -match "App_Config|Resources|bin"}
my apologies to all for the trouble. right i have manage to right a new one, which kind of works but not completely. it zips up the zip folder(for example) in a directory into on big zip, but it takes all the files in the directory. even though i am trying to specify to pick only the .zip folders. i have not done error handling yet. all i want to do is once this one is working, is try to zip folders into one big zip folder. if this works then i can try to figure out to zip similiar name file into one zip folder.
So, after formatting your code in the PowerShell ISE, it looks like your switch block isn’t working like you think it should. Each of your conditions are the same ($_) so you are executing the code in all 3 of them every time. And I don’t see anything that defines the $ eadyfile or $match variables, so we’re still missing something…
How are you executing this script? Is it saved as a .ps1 and then run? Or is this a transcript from you typing stuff into a console?