Answer the question
In order to leave comments, you need to log in
How to pass data from an array to a script?
What I do: I
create a list of files to create variables, to pass them to openssl and symmetric encryption.
The script below works, but it only works if you hardcode the in and out variables, while specifying which line should be used.
Question:
How to make the whole array in variables processed automatically.
$src = Get-ChildItem -r B:\backup\ -include *.xls | Where-Object {$_.LastWriteTime -ge [datetime]::Today.AddHours(-24)}
$in = Get-ChildItem $src | % { $_.fullname }
$out = Get-ChildItem $src | % { $_.Name }
cd r:\test
$key = "l:\key\key.bin"
& 'C:\Program Files (x86)\OpenSSL\bin\openssl.exe' enc -e -aes-256-cbc -kfile $key -in $in.getvalue(0) -out $out.GetValue(0)
$in:
B:\backup\ Файл1.xls
B:\backup\ Файл2.xls
B:\backup\ Файл3.xls
B:\backup\ Файл4.xls
$out:
Файл1.xls
Файл2.xls
Файл3.xls
Файл4.xls
Answer the question
In order to leave comments, you need to log in
I think it's here:
$in = Get-ChildItem $src | % { $_.fullname }
$out = Get-ChildItem $src | % { $_.Name }
$src = Get-ChildItem -r B:\backup\ -include *.xls | Where-Object {$_.LastWriteTime -ge [datetime]::Today.AddHours(-24)}
cd r:\test
$key = "l:\key\key.bin"
foreach($item in $src){
& 'C:\Program Files (x86)\OpenSSL\bin\openssl.exe' enc -e -aes-256-cbc -kfile $key -in $item.fullname -out $item.name
}
Thank you for the direction, partially done.
Problem:
Foreach can only handle 1 ($in in $ins), also need to change second $out variable, but forceach doesn't support pipeline...
ForEach ($ins In $in) {& 'R:\test\OpenSSL\bin \openssl.exe' enc -e -aes-256-cbc -kfile $key -in $ins -out $out}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question