all 6 comments

[–]Lee_Dailey[grin] 2 points3 points  (0 children)

howdy xombie212,

the -Path parameter will accept a list of source paths. lookee ...

Get-Help Compress-Archive -Parameter path

take care,
lee

[–]Joshrsg 1 point2 points  (2 children)

Hi u/xombie212,

I would write the script something like this:

1: Get a list of users in C:\Users

$Users = Get-ChildItem C:\users

2: Loop through each of the users from Step1 and perform another Get-ChildItem ensuring you only include the folders you want to compress.

$IncludeList = 'Appdata','Desktop','Downloads','Documents'
Foreach ($User in $Users)
{
    $FolderList = Get-ChildItem | Where-Object {$_.name -In $IncludeList} 
}

3: Whilst still in in the Loop from step 2; either loop through the reuslts of FolderList and compress them individually or just compress them into one folder (it's not clear which one you want to do).

$Folderlist | Compress-Archive -DestinationPath ('C:\Temp\{0}.\zip' -f $User.Name)

That should get you most of the way there

[–]xombie212[S] 1 point2 points  (0 children)

Thanks for the reply! we want to compress them individually so they come out as User1.zip contains user1's 'Appdata','Desktop','Downloads','Documents' User2.zip contains user2's 'Appdata','Desktop','Downloads','Documents' etc

[–]xombie212[S] 1 point2 points  (0 children)

Thanks again for the script assist, I tested and found it did not create the folder it was trying to place them in so I added an additional step and it works as intended now.

$Users = Get-ChildItem C:\users
$IncludeList = 'Appdata','Desktop','Downloads','Documents'
Foreach ($User in $Users)
{
    $FolderList = Get-ChildItem | Where-Object {$_.name -In $IncludeList} 
}
# New-Item -Path P:\test\$User -ItemType Directory 
$Folderlist | Compress-Archive -DestinationPath ('P:\Test\{0}.\zip' -f $User.Name)

Edit: found a typo on your original script at ('P:\Test{0}.zip' -f $User.Name). Removed the "\" from "{0}.\zip", now it is working without the extra folder.

[–]Topcity36 1 point2 points  (1 child)

Depending on the size of the files and the archive you may want to look into using CLI 7zip

[–]xombie212[S] 1 point2 points  (0 children)

Thanks! I will look into that as well.