Building a 7-zip command string in powershell
===

My first excursion into a real app in Powershell; I could write the code in a traditional .Net language, but I think Powershell is ideal for console apps like this. I've searched StackOverflow and found the (nearly) exact script I need; my issue is that I want to take a folder of files (on server fsA) and create 7-Zip archives on fsB named by the file date. For instance, all the files that were last written on 7/21/12 would be found in archive 20120721.7z. I'm basing this on the solution found here: http://stackoverflow.com/questions/6473973/create-a-7z-archive-for-files-created-by-date-using-powershell?rq=1

Here is what I have so far:

    $prog_dir = "C:\Progra~1\7-Zip\7z.exe"
    $archive_dir = "\\fsa\Backup"
    $input_dir = "\\fsb\Xml\Archive\"
    $7zOpts = "-m0=PPMd:o32:mem192M"
    $groups = dir $input_dir | group-object -property {$_.LastWriteTime.Date}
    $groups | foreach{$cmd = $prog_dir + " a " + $archive_dir + "\$((Get-Date $_.Name).ToString(`"yyyyMMdd`")).7z $([string]::join(`" `", $_.Group)) " + $7zOpts} #; invoke-expression $cmd}
    #
    #Where to put this: "+ $input_dir +"???
    #
    $cmd

I can't seem to find a way to specify the input directory in the foreach line; I can put it at the beginning of the join statement, but it only adds the input directory to the first file in the list. For instance:

    $groups | foreach{$cmd = $prog_dir + " a " + $archive_dir + "\$((Get-Date $_.Name).ToString(`"yyyyMMdd`")).7z " + $input_dir + "$([string]::join(`" `", $_.Group)) " + $7zOpts} #; invoke-expression $cmd}

produces the output

C:\Progra~1\7-Zip\7z.exe a \\\fsa\Backup\20120722.7z \\\fsb\Xml\Archive\255IQR.xml 2573WV.xml 257RMC.xml

where the last two files do not have the full path prepended? What am I doing wrong?

