elwayisgod
asked on
Need to .zip in a .bat and use built in functionality in Win Server 2016
Windows Server 2016 - Need to zip up all *.txt files in a directory. Client doesn't want to install 7zip. So was thinking Powershell but I have never used it or know how to use it.
My current scripts are .bat
Can I run PShell within a .bat?
I found this example, but not sure how to actually execute it. Can I use my variables I set in my .bat?
Very confused.
My current scripts are .bat
Can I run PShell within a .bat?
I found this example, but not sure how to actually execute it. Can I use my variables I set in my .bat?
Very confused.
https://4sysops.com/archives/zip-and-unzip-with-powershell explains and gives a usage example for powershell.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ASKER
crap... I see it... Hold on...
You mean the additional single quote at the end of the last line in your script? :)
ASKER
Nope... Same Error after changing my Target path....
@echo off
setlocal
set Source=%LOGDIR%\*.log
set Target=%ARCHIVEDIR%\PBCS\Backups\%Timestamp%\%Timestamp%_Logs.zip
powershell.exe -Command "Get-ChildItem '%Source%' | Compress-Archive -DestinationPath '%Target%' -Force"'
exit /b
Looks like you have an extra trailing single quote, remove that.
powershell.exe -Command "Get-ChildItem '%Source%' | Compress-Archive -DestinationPath '%Target%' -Force"'
»bp
powershell.exe -Command "Get-ChildItem '%Source%' | Compress-Archive -DestinationPath '%Target%' -Force"'
»bp
ASKER
didn't see that....Stand by
See https://www.experts-exchange.com/questions/29144411/Need-to-zip-in-a-bat-and-use-built-in-functionality-in-Win-Server-2016.html?anchorAnswerId=42854296#a42854296
Have a look at the very last character in the "powershell ..." line - in your script, it ends with a single quote, which shouldn't be there. The last character should be the closing double quote after -Force
Have a look at the very last character in the "powershell ..." line - in your script, it ends with a single quote, which shouldn't be there. The last character should be the closing double quote after -Force
ASKER
Bingo!! My blind butt :)