Q1. I tried few compressed method but none of it work on my machine. I just can use external zip tool 7z.exe to compressed the file but I dont have the privilege to install the 7z.exe file in serverA nor update the powershell to v5. currently using powershell v2 Tried as below but none of it working. So, any other method can intro me for compressed file?
- Add-Type -assembly "system.io.compression.filesystem"
- Compress-Archive
- Add-Type -Path C:\Reference\Draftdoc.docx
- C:\Reference\Images\diagram2.vsd -CompressionLevel Optimal
-DestinationPath C:\Archives\Draft.Zip
Q2. Below are the query I'm using 7z.exe tools (this serverB does come with 7z.exe) but I encountered error. I want to compress any file with today's date.
$timestamp = (Get-Date).ToString('yyyy-MM')
$source = "D:\csv\*.csv", "D:\csv2\*.csv"
$target = "D:\CSV2_$timestamp.zip"
$7zip = "D:\Program Files\7-Zip\7z.exe"
#Compressed file
if (-not (test-path $7zip)) {throw '$7zip needed'}
set-alias sz $7zip
sz a -mx=9 $target $source
{
Get-ChildItem $source | Where{$_.LastWriteTime -gt (Get-Date).AddDays(-1)}
}
Note: Both server I also need compressed file but ServerA doesnt come 7z, but Server B does come with 7z.exe