Я не уверен, какую версию PowerShell вы используете, похоже на v2, и если это правда, действительно обновитесь до минимальной версии v5x. v2 устарела и больше не поддерживается, если память служит.
Используя PSv5, вы можете просто сделать это ...
Get-ChildItem -Path 'e:\temp' -Recurse -Directory |
ForEach{
Compress-Archive -Path "$($_.FullName)\*.*" -DestinationPath "$($_.FullName)\$($_.Name).zip" -Verbose
}
Перечисленное выше - это ...
Get-ChildItem -Path 'e:\temp' -Recurse -Directory
# Results
Directory: E:\temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 11/15/2018 9:19 PM Leaf1
d----- 11/15/2018 9:19 PM Leaf2
d----- 11/15/2018 9:19 PM Leaf3
Get-ChildItem -Path 'e:\temp' -Recurse -Directory |
ForEach{
Get-ChildItem -Path $_.FullName
}
# Results
Directory: E:\temp\Leaf1
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 11/15/2018 9:19 PM 0 New Bitmap Image.bmp
-a---- 11/15/2018 9:19 PM 0 New Text Document.txt
Directory: E:\temp\Leaf2
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 11/15/2018 9:19 PM 0 New Bitmap Image.bmp
-a---- 11/15/2018 9:19 PM 0 New Text Document.txt
Directory: E:\temp\Leaf3
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 11/15/2018 9:19 PM 0 New Bitmap Image.bmp
-a---- 11/15/2018 9:19 PM 0 New Text Document.txt
Get-ChildItem -Path 'e:\temp' -Recurse -Directory |
ForEach{
Compress-Archive -Path "$($_.FullName)\*.*" -DestinationPath "$($_.FullName)\$($_.Name).zip" -WhatIf
}
# Results
What if: Performing the operation "Compress-Archive" on target "
E:\temp\Leaf1\New Bitmap Image.bmp
E:\temp\Leaf1\New Text Document.txt".
What if: Performing the operation "Compress-Archive" on target "
E:\temp\Leaf2\New Bitmap Image.bmp
E:\temp\Leaf2\New Text Document.txt".
What if: Performing the operation "Compress-Archive" on target "
E:\temp\Leaf3\New Bitmap Image.bmp
E:\temp\Leaf3\New Text Document.txt".
Get-ChildItem -Path 'e:\temp' -Recurse -Directory |
ForEach{
Compress-Archive -Path "$($_.FullName)\*.*" -DestinationPath "$($_.FullName)\$($_.Name).zip" -Verbose
}
# Results
VERBOSE: Preparing to compress...
VERBOSE: Performing the operation "Compress-Archive" on target "
E:\temp\Leaf1\New Bitmap Image.bmp
E:\temp\Leaf1\New Text Document.txt".
VERBOSE: Adding 'E:\temp\Leaf1\New Bitmap Image.bmp'.
VERBOSE: Adding 'E:\temp\Leaf1\New Text Document.txt'.
VERBOSE: Preparing to compress...
VERBOSE: Performing the operation "Compress-Archive" on target "
E:\temp\Leaf2\New Bitmap Image.bmp
E:\temp\Leaf2\New Text Document.txt".
VERBOSE: Adding 'E:\temp\Leaf2\New Bitmap Image.bmp'.
VERBOSE: Adding 'E:\temp\Leaf2\New Text Document.txt'.
VERBOSE: Preparing to compress...
VERBOSE: Performing the operation "Compress-Archive" on target "
E:\temp\Leaf3\New Bitmap Image.bmp
E:\temp\Leaf3\New Text Document.txt".
VERBOSE: Adding 'E:\temp\Leaf3\New Bitmap Image.bmp'.
VERBOSE: Adding 'E:\temp\Leaf3\New Text Document.txt'.
#>
(Get-ChildItem -Path 'E:\Temp' -Filter '*.zip' -Recurse).FullName
# Results
E:\Temp\Leaf1\Leaf1.zip
E:\Temp\Leaf2\Leaf2.zip
E:\Temp\Leaf3\Leaf3.zip