powershell script for file encrypt using slift

Skumar_CCSA
Skumar_CCSA used Ask the Experts™
on
i have multiple files to encrypt using slift software.
I have the manual steps to encrypt but need help for encrypting it.
I have restriction not to store any password in the scripts hence it required password to be encrypted.
command is
slift.exe /e "sourcedirectory" /pfx "privatekeyfile.pfx" password /cer "partnerpublickey.cer"
can help how to script in powershell.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Jose Gabriel Ortega CastroTop Rated Freelancer on MS Technologies
Awarded 2018
Distinguished Expert 2018

Commented:
From source:https://stackoverflow.com/questions/24940243/running-cmd-command-in-powershell
Try this :
$sourceDirectory="C:\Source\Dir"
& "C:\<path>\<ToSlift.exe>\slift.exe /e "$sourceDirectory" /pfx "privatekeyfile.pfx" password /cer "partnerpublickey.cer"

Open in new window


It should be something like that

Author

Commented:
password must be encrypted.
When script run it will should decrypt the password for use.
can help.

Author

Commented:
here is the code i am trying.
want to zip all files from source directory.
Currently it is having plain password readable.
Want to encrypt the password in script, should not readable format.
after successful encryption must give output log.
can help pls.....

# Encrypt Zip Files
$ENCRPath = "E:\ABC\Zip_Source\*.zip"
$ENCRpfxpath = "E:\ABC\Certs\privatekey.pfx"
$ENCRcerpath = "E:\ABC\Certs\publickey.cer"
$ENCRkeypasswd = "textpassword"
"D:\Program Files\SLIFT-Ez Classic\1.5\sliftc.exe" /e $ENCRPath /pfx $ENCRpfxpath $ENCRkeypasswd /cer $ENCRcerpath

Author

Commented:
In this script it use pfx password which is encrypted, while running the script will call decrypt script for password decryption and enter.
I want help to convert this code to powershell, so that all in one script executed.
Pls help....

REM Purpose: Script to Encrypt File
Set CURRTIME=%TEMP%\CURRTIME.TMP
TIME /T > %CURRTIME%
Set PARSEARG="eol=; tokens=1,2* delims=:, "
For /F %PARSEARG% %%i in (%CURRTIME%) Do SET HH=%%i
Set PARSEARG="eol=; tokens=1,2* delims=:, "
For /F %PARSEARG% %%i in (%CURRTIME%) Do SET SS=%%j
rem echo %YYYY%-%MM%-%DD%-%HH%-%SS%
FOR /f "tokens=1-4 delims=/ " %%a in ('date/t') do SET date=%%d%%b%%c
FOR /f "tokens=1-3 delims=: " %%i in ('time/t') do SET time=%%i%%j%%k
SET logpath=E:\Test\Working directory\logs\Encrypt_%DATE%%TIME%.txt
SET pfxpath=E:\Test\Working directory\personal.pfx
SET certpath=E:\Test\Working directory\vendor.cer
SET pwd_path="E:\Test\Working directory\EncrPass.txt"
SET decrypt_script_path="E:\Test\Working directory\Decrypt.ps1"

REM Encrypt File
FOR /f "delims=" %%a IN (' %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass %decrypt_script_path% %pwd_path% ') DO (
      SET keypasswd=%%a
      )
REM Execute Encrypt file
ECHO Start Encryption of files >> %logpath%
ECHO OFF
FOR %%i IN ("E:\ABC\Zip_Source\*.zip") DO (
      "D:\Program Files (x86)\PrivyLink\SLIFT-Ez Classic\1.5\sliftc.exe" /e "%%i" /pfx %pfxpath% %keypasswd% /cer %certpath% verbose >> %logpath%
      )
ECHO ON
END
Decrypt.ps1
EncryptPWD.ps1
EncrPass.txt
I made it work with searching online...
try{
    $fileName = $Sfiles[$i].FullName
    $BkpMoveFile = "$backupFolder\$($sfiles[$i].BaseName)_$date.zip"
         & "D:\Program Files (x86)\PrivyLink\SLIFT-Ez Classic\1.5\sliftc.exe" /e $fileName /pfx $pfxpath $Paswod /cer $certpath /verbose | Out-File $Logfile -Append
        #successful Encrypt
        $msj="Moving Encrtpted File ""$sfiles"
        Move-Item -Path $($fileName) -Destination $BkpMoveFile -Force
}
catch{
	$msj="There was an Error: $($_.exception.Message)"
}

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial