Passing Variable to 7zip from powershell -


i can see there have been similar question answered nothing seems have answers i'm looking for, have tried using solutions/modifying them suit needs unable correct outputs.

my main question is: can pass powershell variables 7zip's command line.

currently have script:

##########alias setting########## if (-not (test-path "$env:programfiles\7-zip\7z.exe")) {throw "$env:programfiles\7-zip\7z.exe needed"} set-alias sz "$env:programfiles\7-zip\7z.exe"  ############################################ #### variables   $filepath = "d:\logs\test\201310\" #location in  $archive = "d:\logs\test\201310\"  $extension = "*.log" #extensions  $days = "30" #number of days past today's date archived  $cutday = [datetime]::now.adddays($days)  $log = get-childitem $filepath -include $extension -recurse | where-object {$_.lastwritetime -lt $cutday}  ########### end of varables ##################   foreach ($file in $log)   #current gui output - temp using debugging purpose if required , confirm files.     {         write-host "file name : $file " $file.lastwritetime      }      foreach ($file in $log) # zipping    {     $archivename = $_.cutday       sz -t7z $archivename $archivename -m0=ppmd    }  ########### end of script ########## 

what have have 7zip command line read file name , destination variables, plan try , make generic script possible $archivename depend on folder name , current date.

i script able read locations zipping via parameters cannot read variables!

any appreciate or if require clarification please let me know.

i figured out best way pass parameter executable using splatting parameter (@variablename):

$7zippath = "$env:programfiles\7-zip\7z.exe"  $parameter = @('a', '-t7z', '-m0=ppmd', "$target", "$source") &$7zippath @parameter 

sz -t7z $archivename $archivename -m0=ppmd

there 2 $archivename variables pass 7zip. first should target (e.g. c:\test.zip) , second source (e.g c:\test.text)


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -